Forums Register Login

Buffered Reader unable to read local file..

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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)));
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1755 times.
Similar Threads
Read integers from a file
Tokens
I/O: searching an address book text file
Syntax error in INSERT INTO statement
sting tokenizer in a loop(vv urgent)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:13:10.