• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Anyone help me out with this error

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic