It's not a secret anymore!
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
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: 15302

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
jQuery in Action, 3rd edition