package com.sxt.prac; /* * 缓冲流之字符缓冲流 defaultCharBufferSize = 8192; * 1.读入到程序 * 2.程序写到文件 * 3.采用循环边读边写 * 两个独有的方法: * BufferedReader br.readLine();//读内容 没有返回null * BufferedWriter bw.newLine; */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class TestBuffered { public static void main(String[] args) throws IOException { //读入 BufferedReader br = new BufferedReader(new FileReader(new File("G:\\testBufferedSource.txt"))); //写出 BufferedWriter bw= new BufferedWriter(new FileWriter(new File("G:\\testBuffered.txt"))); String line = null; //循环边读边写 while((line = br.readLine()) != null){// bw.write(line); bw.newLine();// } br.close(); bw.close(); System.out.println("----------end"); } }
时间: 2024-10-25 16:07:28