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);
    }
}

 

posted @ 2022-11-30 19:11  Bonnie_ξ  阅读(91)  评论(0编辑  收藏  举报