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("关闭失败");
}
}
}
}
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("关闭失败");
}
}
}
}