java 修改文件名

时间:2023-03-08 16:47:51
java 修改文件名
    // 修改文件名

    public static boolean modifyFileName(String serverPath, String oldFileName,
String newLoginNo) {
String oldPath = serverPath + "/" + oldFileName;
String newPath = serverPath + "/" + newLoginNo + "-"
+ oldFileName.substring(oldFileName.indexOf('-') + 1);
File oldFile = new File(oldPath);
File newFile = new File(newPath);
if (oldFile.renameTo(newFile)) {
return true;
} else {
return false;
}
}