java文件移动

  1. /** 
  2.  * 移动文件到指定的目录 
  3.  *  
  4.  * 将文件从test文件夹移动到test2文件夹
  5.  *  
  6.  */  
  7. public class MoveFile {  
  8.   
  9.     public static void main(String[] args) {  
  10.         try {  
  11.             File afile = new File("C:\test\test.txt");  
  12.             if (afile.renameTo(new File("C:\test2\" + afile.getName()))) {  
  13.                 System.out.println("File is moved successful!");  
  14.             } else {  
  15.                 System.out.println("File is failed to move!");  
  16.             }  
  17.         } catch (Exception e) {  
  18.             e.printStackTrace();  
  19.         }  
  20.     }  
  21. }
原文地址:https://www.cnblogs.com/Darkqueen/p/8966048.html