字符缓冲流
将文本写入字符输出流,缓冲各个字符,从而提供单个字符、数组和字符串的高效写入
|
|
//父类Writer中的方法
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException { /* BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("4.txt")); String str = "你好,昆明"; bufferedWriter.write(str); bufferedWriter.newLine(); //直接写入一个换行,不用考虑系统平台 bufferedWriter.write(str); bufferedWriter.close(); / BufferedReader bReader = new BufferedReader(new FileReader("4.txt")); / char[] cbuf = new char[4]; bReader.read(cbuf); System.out.println(new String(cbuf)); / //你好,昆 / String readLine; while( ( readLine = bReader.readLine() ) != null){ System.out.println(readLine); } bReader.close();*/ |
//使用 BufferedReader BufferedWriter 复制 BufferedReader bufferedReader = new BufferedReader(new FileReader("11.java")); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("copy.java")); //逐行复制 String string = null; while( (string = bufferedReader.readLine()) != null ){ bufferedWriter.write(string); bufferedWriter.newLine(); //读完一行写一行不会把回车换行写进去,所有要自己写换行 } bufferedReader.close(); bufferedWriter.close(); } } |