This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problems reading file" Watch "Problems reading file" New topic

Problems reading file

tom rubbens

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"); reader = new;
String line;
while((line = in.readLine()) != null) {
catch (FileNotFoundException e) {
System.out.println("error file");
catch (IOException e) {
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

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
I agree. Here's the link:
subject: Problems reading file
Similar Threads
Query in code of displaying a text file
Help reading File
Data lost when writing object to a file
Problems reading file
How to load a file in jar file