Java tutorial mentions that one of the uses of Finally section is to close any open IO streams. That's what I did in the following code. However, I get "IoTest2.java [30:1] unreported exception java.io.IOException; must be caught or declared to be thrown" error when I compile the code. How should I hadle exceptions thrown in Finally section?
import java.io.*;
public class IoTest2 {
/** Creates a new instance of IoTest2 */
public IoTest2() {
}
public static void main(
String[] args){
File f1 = new File("c:\\testfile");
FileReader in = null;
try {
f1.createNewFile();
in = new FileReader(f1);
} catch(IOException e) {
System.out.println(e.getMessage());
} finally {
in.close();
}
}
}