字符流 BufferedWriter寫入數據

創建student.txt文件,並用BufferedWriter寫入字符串和換行符 

import java.io.*;

public class IOTest06 {
    public static void main(String[] args) throws IOException {
        FileWriter fw = new FileWriter("F:/student.txt");
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write("This is my student.txt"); //向文件中寫入字符串
        bw.newLine();   //換行
        bw.write("這是我的文件");
        bw.close(); //關閉流
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章