public class Test1 {
public static void main(String[] args) {
FileWriter fw =null;
try {
fw=new FileWriter("k:\\tst.txt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
//一定要判断不为空,否则如果对象创建不成功,会报空指针异常
if(fw!=null){
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}
}
public static void main(String[] args) {
FileWriter fw =null;
try {
fw=new FileWriter("k:\\tst.txt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
//一定要判断不为空,否则如果对象创建不成功,会报空指针异常
if(fw!=null){
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}
}
}
}