java每日一練------檔案寫
阿新 • • 發佈:2018-11-19
import java.io.*;
public class WriteFile {
public static String basedir = "你的目錄";
public static void main(String []args) {
writerfile();
}
public static void writerfile() {
BufferedWriter bfw = null;
try {
//true: 內容以追加方式新增,此引數不寫表明是重寫此檔案
bfw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(basedir),true),"utf8"));
bfw.write("sf\r\n");
}catch(Exception e) {
e.printStackTrace();
}finally {
try {
if(bfw!=null) {
bfw.close();
}
}catch(IOException e) {
e.printStackTrace();
}
}
}
}