java file move

  1. /** 
  2.  * Move the file to the specified directory 
  3.  *  
  4.  * Move files from test folder to test2 folder
  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. }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325022431&siteId=291194637