Java 文件重名
package cn.strivepine.util;
import java.io.File;
/**
* @Author StrivePine
* @data 2022/5/13 14:30
* @Explain
*/
public class FileName {
//重命名文件方法
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:\\test\\txt\\aaa1.txt";
String targetFolderPath = "D:\\test\\qqqq.csv";
reNameFile(sourceFolderPath, targetFolderPath);
}
}
输出结果展示: