package com.jackie.io.readfile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class CopyFile {
	public static void main(String[] args) {
		//建立联系   确保源文件必须存在
		//目标文件可以不存在
		String srcPath = "E:/workspace/newFile.txt";
		String destPath = "E:/workspace/destFile.txt";
		File src = new File(srcPath);
		File dest = new File(destPath);
		//选择流
		InputStream is = null;
		OutputStream os = null;
		byte[] byteArr = new byte[1024];
		int len = 0;
		try {
			//操作
			is = new FileInputStream(src);
			os = new FileOutputStream(dest);
			while(-1 != (len =is.read(byteArr))){
				os.write(byteArr, 0, len);
			}
			os.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			//释放资源
			if(os != null){
				try {
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(is != null){
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

}
最近下载更多
无名氏111  LV32 2023年5月23日
1090032627  LV2 2021年8月14日
帅气你虎哥  LV7 2021年7月5日
崔牛逼  LV8 2020年12月18日
擦鞭你最帅  LV6 2020年11月30日
huigui  LV2 2020年6月15日
xu1158450076  LV2 2019年11月27日
oldfox  LV18 2019年3月23日
han108  LV16 2019年3月6日
heart426  LV11 2018年10月13日
最近浏览更多
WBelong  LV7 2023年12月19日
无名氏111  LV32 2023年5月23日
yyyyyyzh  LV8 2022年12月9日
yuanye985 2022年1月11日
暂无贡献等级
tangjj7260  LV18 2021年12月25日
ideaCode  LV4 2021年9月29日
cc900118  LV17 2021年8月26日
雨凤凰  LV4 2021年8月25日
1090032627  LV2 2021年8月14日
帅气你虎哥  LV7 2021年7月5日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友