不多说,直接上干货!
CopyTextByBufTest.java
package zhouls.bigdata.DataFeatureSelection.test; 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 CopyTextByBufTest { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { FileReader fr = new FileReader("a.txt"); BufferedReader bufr = new BufferedReader(fr); FileWriter fw = new FileWriter("b.txt"); BufferedWriter bufw = new BufferedWriter(fw); String line = null; while((line=bufr.readLine())!=null){ bufw.write(line); bufw.newLine(); bufw.flush(); } bufw.close(); bufr.close(); } }