Private voidmovetotherfolders (String pathname,string filename,string anspath) {string startpath = This. path + pathName + File.separator +FileName; String endpath = Anspath + file.separator + currentdate +File.separator; Try{File Startfile=NewFile (Startpath); File tmpfile=NewFile (Endpath);//Get folder path if(!tmpfile.exists ()) {//determine if a folder is created, create a new folder without creating itTmpfile.mkdirs (); } System.out.println (Endpath+startfile.getname ()); if(Startfile.Renameto(NewFile (Endpath +startfile.getname ()))) {System.out.println ("File is moved successful!"); Log.info ("File moved successfully!" File name: "{}" target path: {} ", Filename,endpath); } Else{System.out.println ("File is failed to move!"); Log.info ("File move failed!" File name: "{}" Start path: {} ", Filename,startpath); } } Catch(Exception e) {log.info ("File Move exception!" File name: "{}" Start path: {} ", Filename,startpath); }}
The function of this method is to move the file filename under Startpath to Endpath
Java moving files to another directory