/**
* @Author: ljh
* @Description: 转移文件
* @DateTime: 14:48 2023/2/15
* @Params: oldFilePath 原文件夹路径 newFilePath新文件夹路径
* @Return
*/
public static void renameToFiles(String oldFilePath, String newFilePath) {
try {
File oldFile = new File(oldFilePath);
File newFile = new File(newFilePath);
//创建新文件夹
newFile.mkdirs();
//获取该文件夹下所有文件
File[] files = oldFile.listFiles();
for (File f : files) {
if (f.isFile()) {
//转移文件到新文件夹内
f.renameTo(new File(newFilePath + f.getName()));
}
}
//删除原有文件夹
oldFile.delete();
} catch (Exception e) {
logger.error("moveInFile2Reject Failed", e);
}
}
java实现转移文件位置
最新推荐文章于 2023-04-10 11:00:47 发布