小猿圈之java文件重命名

隨着互聯網的迅速發展,it行業愈來愈火,學習java的人愈來愈多,小猿圈今天給你們說一下java對文件怎麼重命名的,但願朋友們看後,能夠學到這個小技巧。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);

        }

    }

你們看後感受很簡單吧,在小猿圈帶領學習下,全部不容易理解的問題,咱們都會用簡單容易理解的小實例幫助你們掌握這個知識點,但願你們能夠愉快的學習,有效率的掌握。code

相關文章
相關標籤/搜索