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); } }
故乡明