File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Problems reading file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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...


GenRocket - Experts at Building Test Data
 
 
subject: Problems reading file