package test; import java.io.*; public class FileCopy { public static void main(String[] args) throws Exception { File src = new File("C:\\清单13-5.txt"); File dest = new File("C:\\to.txt"); copyTextFile(src, dest); } static void copyTextFile(File src, File dest) throws Exception { BufferedReader in = new BufferedReader(new FileReader(src)); PrintWriter out = new PrintWriter(dest); String temp = in.readLine(); StringBuilder result = new StringBuilder(); while (temp != null) { result.append(temp + "\n"); temp = in.readLine(); } out.write(result.toString()); out.flush(); in.close(); out.close(); } }
时间: 2024-10-09 08:43:23