Java I/O异常的处理

package io_test;


import java.io.FileWriter;
import java.io.IOException;


public class IOExceptionDemo {


private static final String LINE_SEPARATOR = System.getProperty("line.separator");


public static void main(String[] args) {
FileWriter fw =null;
try {
fw = new FileWriter("demo.txt", true);
fw.write("abc" + LINE_SEPARATOR + "def");

} catch (Exception e) {
// TODO: handle exception
if(fw !=null)
try {
fw.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
throw new RuntimeException("关闭失败");
}
}

}


}

你可能感兴趣的:(Java I/O异常的处理)