package com.itcast;
import java.io.*;
public class IoDemo {
public static void main(String[]args)throws IOException
{
FileWriter fw=null;
try
{
fw=new FileWriter("I:\\Demo.txt");
fw.write("jkdsfhgkja");
}
catch(IOException e)
{
System.out.println(e.toString());
}
finally
{
try
{
if(fw!=null)如果此处的fw为空了下面的关闭不就执行不到了吗?系统支援还是要被占用啊???这样写合适吗
fw.close();
}
catch(IOException e)
{
System.out.println(e.toString());
}
}
}
} |