Package cn.com; import Java. io. file; // Problem description: Move the file // note: // 1 move the folder in the original path to retain // 2 but the file in the folder will no longer exist // 3 if it is a directory, recursively call this method // 4 Core is call renameto () in file () method public class filetest {public static void main (string [] ARGs) {filetest = new filetest (); filetest. movefile ("f :\\ TE6", "F :\\ te7");} public void movefile (string frompath, string topath) {file fromfolder = new file (frompath ); file [] fromfiles = fromfolder. listfiles (); I F (fromfiles = NULL) {return;} file tofolder = new file (topath); If (! Tofolder. exists () {tofolder. mkdirs () ;}for (INT I = 0; I <fromfiles. length; I ++) {file = fromfiles [I]; If (file. isdirectory () {movefile (file. getpath (), topath + "\" + file. getname (); // You can also delete it // file. delete ();} If (file. isfile () {file tofile = new file (tofolder + "\" + file. getname (); If (tofile. exists () {// You can also delete it // tofile. delete ();} // move the file. renameto (tofile );}}}}