IO
字节流:
InputStream,OutputStream
字符流:
Reader,Writer
IO所有操作都有IOException
*/
import java.io.*;
class FileWriterDemo{
public static void main(String [] args){
FileWriter fw = null;
try{
fw = new FileWriter("FileWriterDemo.txt");
fw.write("aabc");
}catch(IOException e){
System.out.println(e.toString());
}finally{
try{
if(null != fw){
fw.close();
关闭资源一定要执行,放在finally中(外层);
关闭操作有IOException:故 try{}catch{}
创建文件就抛出异常,fw==null ;故需判断
*/
}
}catch(IOException e){
System.out.println(e.toString());
}
}
}
}