首页 > 编程语言 > 详细

Java 拷贝文件内容

时间:2014-12-16 15:10:49      阅读:220      评论:0      收藏:0      [点我收藏+]

说明:

把d盘下a.txt 中的内容复制到e盘下e.txt文件中

	private static void copyDataBase() {
		try {
			File f1 = new File("d:/a.txt");
			File f2 = new File("e:/e.txt");
			InputStream in = new FileInputStream(f1);

			OutputStream out = new FileOutputStream(f2);

			byte[] buf = new byte[1024];
			int len;
			while ((len = in.read(buf)) > 0) {
				out.write(buf, 0, len);
			}
			in.close();
			out.close();
			System.out.println("File copied.");
		} catch (FileNotFoundException ex) {
			System.out.println(ex.getMessage() + " in the specified directory.");
			System.exit(0);
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
	}


Java 拷贝文件内容

原文:http://blog.csdn.net/nmsoftklb/article/details/41959397

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!