This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Buffered Reader unable to read local file..  RSS feed

 
Esther Yun
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I need some help on buffered reader on local file.

The code below is one my class method to read the data of test.


I want to set the File as local file because this application will be run in other computers.
I tried to compile this but ended up getting exception from java.
the data file is saved inside the src folder which contains all my .java files.
For your information I'm using Netbeans 7.1.2.

java.io.FileNotFoundException: subject.dat (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileReader.<init>(FileReader.java:72)
...

so may I know how to let java read my local file?
 
Gopi Chella
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this it will work perfectly and you dont need to give physical path.

BufferedReader reader = new BufferedReader(new InputStreamReader(YourClassName.class.getClassLoader().getResourceAsStream(fileName)));
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!