的生成y.txt只包含一號線爲什麼2號線是abcent爲什麼文件只包含1號線
public class Writer{
public static void main(String[] args) {
try {
FileWriter fw = new FileWriter(new File("y.txt"));
PrintWriter pw1 = new PrintWriter(fw);
pw1.println ("line1 ");
pw1.close();
PrintWriter pw2 = new PrintWriter(fw);
pw2.println("line2 ");
pw2.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
我很確定'pw1.close()'調用'fw.close()'。 – Compass 2014-12-05 18:28:38
你ü正確 我搬pw1.close()下來它工作 謝謝 – DeepBlue0003 2014-12-05 18:30:53