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); } }
标签:重命名,newPath,file,String,demo,targetFolderPath,public From: https://www.cnblogs.com/JYB2021/p/16939492.html