Java 將文件移動到指定目錄


直接上代碼吧

//將文件移動到指定目錄
try {
   File startFile = new File(path.get("read") + files[i].getName());
   File tmpFile = new File(path.get("shift"));//獲取文件夾路徑
   if (!tmpFile.exists()) {//判斷文件夾是否創建,沒有創建則創建新文件夾
      tmpFile.mkdirs();
     }
   if (startFile.renameTo(new File(path.get("shift") + files[i].getName()))) {
       System.out.println("文件移動成功!");
     } else {
         System.out.println("文件移動失敗!");
     }
} catch (Exception e) {
    System.out.println(e);
}                        

 


免責聲明!

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



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