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. }
posted @ 2018-04-28 09:57  up-zyn  阅读(304)  评论(0编辑  收藏  举报