import java.io.FileWriter;
import java.io.IOException;
/*
* 使用try/catch完成IO代码
*/
public class Demo01_IOException {
public static void main(String[] args) {
FileWriter fw = null;
try {
fw = new FileWriter("a/b/c/i.txt");
fw.write("IO真是太有趣了!");
} catch (IOException e) {
System.err.println("异常产生了!");
e.printStackTrace();
} finally {
if(fw!=null) {
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
System.out.println("好多其他代码");
}
}
|
|