码迷,mamicode.com
首页 > 编程语言 > 详细

java 文本文件复制

时间:2015-05-11 12:19:28      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

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();
	}
}

 

java 文本文件复制

标签:

原文地址:http://www.cnblogs.com/reddit/p/4493926.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!