利用java,实现对已存在的文件,进行重命名
package com.javabasic.io;
import java.io.File;
public class FileUtils {
//重命名文件
public static void reNameFile(String oldPath, String newPath) {
boolean result = new File(oldPath).renameTo(new File(newPath));
System.out.println("重命名的结果:" + result);
}
//测试方法
public static void main(String[] args) {
String sourceFolderPath = "D:/demo/aaa-20220307.txt";
String targetFolderPath = "D:/demo/aaa.txt";
reNameFile(sourceFolderPath, targetFolderPath);
}
}