Java 文件重命名
/**
* 重命名文件
* @param fileName
* @return
*/
public static void renameFile(String filePath, String fileName) {
SimpleDateFormat fmdate = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String oldFileName = filePath+"/"+fileName;
File oldFile = new File(oldFileName);
String newFileName = filePath+"/"+fileName.split("\\.")[0]+fmdate.format(new Date())+"."+fileName.split("\\.")[1];
File newFile = new File(newFileName);
if (oldFile.exists() && oldFile.isFile()) {
oldFile.renameTo(newFile);
}
}