【FileOutputStream类:文档中的换行与追加】

package test;

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

/**
 * @author shusheng
 * @description 文档中的换行与追加
 * @Email [email protected]
 * @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();
    }

}

猜你喜欢

转载自www.cnblogs.com/zuixinxian/p/9936011.html
今日推荐