1. 程式人生 > >number (2)變數相關錯誤

number (2)變數相關錯誤

變數沒有被定義

fw cannot be resolved

變數沒有被初始化

正確程式碼

package com.itheima_01;

import java.io.FileWriter;
import java.io.IOException;

public class ExceptionDemo1 {
public static void main(String[] args) {
FileWriter fw=null;
try {
fw =new FileWriter("a.txt");
fw.write("hello");

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
try {
fw.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}