码迷,mamicode.com
首页 > 其他好文 > 详细

文件的复制

时间:2014-10-13 11:13:19      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:io

public static void doCopy(String PrimaryAddress, String NewAddress) {
		FileInputStream fis = null;
		FileOutputStream fos = null;
		try {
			fis = new FileInputStream(new File(PrimaryAddress));
			fos = new FileOutputStream(new File(NewAddress));
			byte [] buf = new byte[1024];
			int len = 0;
			while((len = fis.read(buf)) != -1) {
				fos.write(buf, 0, len);
				fos.flush();
			}
		} catch (Exception e) {
			System.err.println("文件复制失败!");
		}finally{
			try {
				if(fis != null) {
					fis.close();
				}
			} catch (Exception e2) {
				// TODO: handle exception
			}
			try {
				if(fos != null) {
					fos.close();
				}
			} catch (Exception e2) {
				// TODO: handle exception
			}
		}
	}

文件的复制

标签:io

原文地址:http://blog.csdn.net/cs_12/article/details/40039307

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