Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Anyone help me out with this error

 
Adi Peyyala
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had written a small program to read a file(sample.txt). I placed both the program and txt file in the bin directory of the j2sdk1.4.2_04 and having been trying to compile it from the command line.

The error which has been nagging me for a while.....

UNREPORTED EXCEPTION FILE NOT FOUND EXCEPTION

The source code.....

import java.io.*;


public class SimpleTok {

public static void main(String[] args) {


BufferedReader buff = new BufferedReader(new FileReader("sample.txt"));
boolean eof = false;

try {
while(!eof) {
String line = buff.readLine();
if(line == null)
eof = true;
else {
System.out.println(line);
}

}
} catch(Exception e) {

e.printStackTrace();
}
}
}


Thanks!!!

Adi
 
Henry Wong
author
Marshal
Pie
Posts: 20997
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The file reader class can throw a file not found during construction. Either declare your method to throw that exception, or handle it in a try/catch clause.

Or you can even put it into the try/catch cause that you already have in your program.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic