package com.zuidaima.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

import org.apache.commons.io.FileUtils;

import cn.hutool.log.StaticLog;

public class CopyFile {

	public static void copyFileUsingApacheCommonsIO(File source, File dest) throws IOException {
		FileUtils.copyFile(source, dest);
	}

	public static void copyFileUsingJava7Files(File source, File dest) throws IOException {
		Files.copy(source.toPath(), dest.toPath());
	}

	/**
	 * 复制单个文件
	 * 
	 * @param oldPath String 原文件路径 如:c:/fqf.txt
	 * @param newPath String 复制后路径 如:f:/fqf.txt
	 * @return boolean
	 */
	public static void copyFile(String oldPath, String newPath) {
		try {
			int byteread = 0;
			File oldfile = new File(oldPath);
			if (oldfile.exists()) { 
				InputStream inStream = new FileInputStream(oldPath);
				FileOutputStream fs = new FileOutputStream(newPath);
				byte[] buffer = new byte[1444];
				while ((byteread = inStream.read(buffer)) != -1) {
					fs.write(buffer, 0, byteread);
				}
				fs.close();
				inStream.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
			StaticLog.info("复制文件失败{}", e.getMessage());
		}
	}
}
最近下载更多
7482166  LV1 2022年12月9日
zw050256  LV7 2022年9月30日
decine  LV1 2022年8月3日
笨小孩一号  LV22 2022年8月2日
crosa_Don  LV18 2022年7月6日
唯一&Mike  LV3 2022年5月1日
xiex909  LV27 2022年3月31日
q13246932  LV1 2022年3月28日
微信网友_5859249697001472  LV1 2022年3月5日
微信网友_5836744970964992  LV1 2022年2月17日
最近浏览更多
操作者 4月10日
暂无贡献等级
WBelong  LV7 3月29日
康日澜  LV9 2023年7月12日
iuchengli 2023年3月17日
暂无贡献等级
7482166  LV1 2022年12月9日
校园网  LV9 2022年11月4日
zw050256  LV7 2022年9月30日
decine  LV1 2022年8月2日
笨小孩一号  LV22 2022年8月2日
crosa_Don  LV18 2022年7月6日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友