//可在指定位置將原有檔案內容更換(舊內容全都會不見),無檔案會自創件

import java.io.*;
import javax.swing.*;
class WriteFile
{
public static void main(String[] args)
{

try
{
String fpath = JOptionPane.showInputDialog("請輸入檔案路徑");
BufferedWriter fout=
new BufferedWriter( new FileWriter(fpath));
fout.write("檔案寫入測試");
fout.newLine();
fout.write("寫入第二行");
fout.newLine();
fout.write("neo");
fout.newLine();
fout.close();
JOptionPane.showMessageDialog(null,fpath+"寫檔完成");
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null,"輸入檔案路徑有誤!!");
}
catch (Exception e)
{}
System.exit(0);

}
}
arrow
arrow
    全站熱搜

    Neo Chao 發表在 痞客邦 留言(0) 人氣()