lizm166

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

 

分类:

技术点:

相关文章:

  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
  • 2021-10-09
  • 2021-12-11
  • 2021-06-17
猜你喜欢
  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
  • 2021-11-18
  • 2022-02-13
  • 2021-11-18
相关资源
相似解决方案