Java文件的复制与剪切
Java文件的其他操作也会在这个专栏下更新
- 文件复制
/**
* 复制文件
* @param sourcePath 源文件路径
* @param newPath 新文件路径
* @return 新文件
*/
public static File copyFile(String sourcePath, String newPath) {
//参数校验
if (StringUtils.isEmpty(sourcePath) || StringUtils.isEmpty(newPath)) {
return null;
}
File newFile;//要返回的新文件
try {
newFile = new File(newPath);//创建新文件
File sourceFile = new File(sourcePath);//源文件
FileInputStream inputStream = new FileInputStream(sourceFile)