Java 文件重命名


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM