Click to See Complete Forum and Search --> : Problem with streams


salientking
02-17-2006, 04:31 AM
Im new to java, trying to print out this stream but i keep getting errors.

char[] input = new char[40];
String fileName = "input.txt";
File myFile = new File(fileName);

PushbackReader in = new PushbackReader(
new BufferedReader(
new FileReader(myFile)));

in.read(input);
System.out.println(input);

and the errors i get...


Proj1.java:30: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
new FileReader(myFile)));
^
Proj1.java:32: unreported exception java.io.IOException; must be caught or declared to be thrown
in.read(input);
^

Khalid Ali
02-17-2006, 11:36 AM
you need to enclose your code within try and catch block
e.g
try{

}catch(java.io.FileNotFoundException nfe){
nfe.printStackTrace();
}catch(java.io.IOException ioe){
ioe.printStackTrace();
}