786snow
Programmer
- Nov 12, 2006
- 75
Hi, I am trying to understand how exception work. I understand the code below.
But I do not understand in the following code they decalaed "throws IOException' in the method declaration with out any catch and try, how does that work?
Code:
try {
BufferedReader in = new BufferedReader(new FileReader("infilename.txt"));
String str;
while ((str = in.readLine()) != null) {
//process(str);
System.out.print("it did not works");
}
in.close();
}
catch (FileNotFoundException ex) {
System.out.print("file not found");
}
}
catch (IOException e) { System.out.print("file can not be opened");
e.printStackTrace();
}
}
But I do not understand in the following code they decalaed "throws IOException' in the method declaration with out any catch and try, how does that work?
Code:
public void readFile(Sring filename) throws IOException {
while (numBytes <= myBuffer.length){ myInputStream.read(myBuffer);
nymByres;++
}