File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Anyone help me out with this error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Anyone help me out with this error" Watch "Anyone help me out with this error" New topic
Author

Anyone help me out with this error

Adi Peyyala
Greenhorn

Joined: Jan 17, 2005
Posts: 6
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
Sheriff

Joined: Sep 28, 2004
Posts: 18824
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Anyone help me out with this error