【IO流】11 - 字节输出流 - 续写&换行

 

package cn.itcast.io.c.bytestream.write;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class FileOutputStreamDemo2 {

    private static final String LINE_SEPARATOR = System.getProperty("line.separator");//换行

    /**
     * @param args
     * @throws FileNotFoundException 
     */
    public static void main(String[] args) throws Exception {
        
        //需求:将数据续写到已有文件中。
        //FileOutputStream(File file, boolean append) 续写。
        //在下一行写入新的数据。

        File file = new File("tempfile\\file.txt");
        
        FileOutputStream fos = new FileOutputStream(file, true);
            
        String str = LINE_SEPARATOR+"itcast";
        fos.write(str.getBytes());
        
        fos.close();
        
    }

}

 

posted @ 2018-01-29 23:39  清风拂柳  阅读(217)  评论(0编辑  收藏  举报