import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Arrays; public class TestFileWriter { public static void main(String[] args) throws IOException { File i = new File("D:\Huang\123.txt"); FileReader r = new FileReader(i); FileWriter w = new FileWriter("D:\Huang\abcd.txt"); StringBuilder sb = new StringBuilder(); int b = -1; char[] cs = new char[(int) i.length()]; int num = 0; System.out.println(i.length()); while ((b = r.read(cs)) != -1) { sb.append(cs); System.out.println((num++) + Arrays.toString(cs)); System.out.println((num++) + String.valueOf(cs));//打印输出时 会输出空格 } w.write(sb.toString()); w.flush(); r.close(); w.close(); }