java 文本文件复制

时间:2015-05-11 12:19:28   收藏:0   阅读:120
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();
	}
}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!