aspose 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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 18116
    
  39

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
 
Similar Threads
Java IO Doubt
how to read lines from a file
count how many tokens are in the first line
incomparable types: boolean and null
output a literal '?'