首页 > 技术文章 > 【FileOutputStream类:文档中的换行与追加】

zuixinxian 2018-11-09 16:56 原文

package test;

import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author shusheng
 * @description 文档中的换行与追加
 * @Email shusheng@yiji.com
 * @date 2018/11/9 14:50
 */
public class FileOutputStreamDemo3 {

    public static void main(String[] args) throws IOException {
        /**
         *换行:
         *不同的操作系统的换行符不同:Windows的为\r\n, linux:\n, Mac:\r
         *追加:
         *把FileOutputStream("fos.txt")改为FileOutputStream("fos.txt",true)
         */
        FileOutputStream fos = new FileOutputStream("fos.txt",true);
        for(int x=0; x<10; x++){
            fos.write(("hello"+x).getBytes());
            fos.write(("\n").getBytes());
        }
        fos.close();
    }

}

 

推荐阅读