Java_基础—readLine()和newLine()方法

package com.soar.chario;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Demo4_Buffered {
    /*
     * 带缓冲区的流中的特殊方法
     * readLine()属于BufferedReader
     * newLine()属于BufferedWriter
     * 
     * newLine 和 \r\n的区别
     * newLine是跨平台的方法
     * \r\n只支持的是windows系统
     */
    public static void main(String[] args) throws IOException {
        //readLine();
        BufferedReader br = new BufferedReader(new FileReader("zzz.txt"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("aaa.txt"));

        String line;
        while((line = br.readLine()) != null){
            bw.write(line);
            //bw.newLine();             //写出回车换行符
            bw.write("\r\n");
        }

        br.close();
        bw.close();
    }

    private static void readLine() throws FileNotFoundException, IOException {
        BufferedReader br = new BufferedReader(new FileReader("zzz.txt"));
        String line;

        while((line = br.readLine()) != null){
            System.out.println(line);
        }

        br.close();
    }

}

你可能感兴趣的:(Java_IO)