close
//跟上一個差不多,用途不同,這能更改內容,但原有內容不會刪除
import java.io.*;
import javax.swing.*;
class WriteAppend
{
public static void main(String[] args)
{
try
{
String fpath = JOptionPane.showInputDialog("請輸入檔案路徑");
String newdata = JOptionPane.showInputDialog("請輸入新增的資料");
BufferedWriter fout=
new BufferedWriter(new FileWriter(fpath,true));
fout.write(newdata);
fout.newLine();
fout.close();
JOptionPane.showMessageDialog
(null,fpath+"寫檔完成\n加入" + newdata);
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null,"輸入檔案路徑有誤!!");
}
catch (Exception e)
{}
System.exit(0);
}
}
全站熱搜