aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Problems reading file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Problems reading file" Watch "Problems reading file" New topic
Author

Problems reading file

tom rubbens
Greenhorn

Joined: Feb 27, 2004
Posts: 2
i'm working in the path c:/info3/be/kahosl
there i have my Test2.class with following code:
package be.kahosl;
...
try {
FileInputStream istream = new FileInputStream("/be/kahosl/test.txt");
java.io.BufferedReader reader = new java.io.BufferedReader(istream);
String line;
while((line = in.readLine()) != null) {
jTextArea1.setText(line);
System.out.println("OK");
}
}
catch (FileNotFoundException e) {
System.out.println("error file");
}
catch (IOException e) {
System.out.println("error");
}
as you c i'm trying to read the file test.txt who is in the same folder as my class and my class is package be.kahosl. I always get: error file... does anyone know what i'm doing wrong?
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Welcome to the Ranch Tom.
I think the first forward slash in the string representing the path to the file is interpreted as the root of the filesystem. That is an abolute path, but the file is not in c:\be\khsol\ directory.
A BufferedReader needs a Reader for construction. But an InputStream "is" not such class.


SCJP2. Please Indent your code using UBB Code
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

Although this is probably happening in a SWING GUI of some sort. It really doesn't pertain so Swing at all. So I am moving it to I/O and Streams...
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Problems reading file
 
Similar Threads
Help reading File
How to load a file in jar file
Data lost when writing object to a file
Problems reading file
Query in code of displaying a text file