IO异常的处理
import java.io.FileWriter;
import java.io.IOException;
public class FileWriterDemo2 {
public static void main(String[] args) {
FileWriter fw = null;
try {
fw = new FileWriter("h:\\demo.txt");
fw.write("abcdefg");
} catch (IOException e) {
e.printStackTrace();
} finally { //close放在finally中
try {
if (fw != null)
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
还没有评论,来说两句吧...