Java recursion allows you to copy, paste, and delete operating system files. java Recursion
Use Java IO recursion to copy, paste, and delete files in the operating system. Cut = copy + paste + Delete
Sample Code:
Import java. io. bufferedInputStream; import java. io. bufferedOutputStream; import java. io. dataInputStream; import java. io. dataOutputStream; import java. io. file; import java. io. fileInputStream; import java. io. fileOutputStream; import java. io. IOException;/*** achieve file copy and delete using recursion ** @ author ForeverLover **/public class FileCopyAndDelete {// delete files of this path public void del EteFile (String path) {File f = new File (path); if (f. isDirectory () {File [] file = f. listFiles (); for (File file1: file) {this. deleteFile (file1.toString (); file1.delete () ;}} else {f. delete ();} f. delete ();} // copy files from path1 to path2 public void copyFiles (String path1, String path2) throws IOException {File f = new File (path1); if (f. isDirectory () {File file = new File (path2); I F (! File. exists () file. mkdir (); File [] file1 = f. listFiles (); for (File file2: file1) {copyFiles (file2.toString (), path2 + "/" + file2.getName () ;}} else {copy (path1, path2) ;}}// copy file from path1 to path2 one by one public void copy (String path1, String path2) throws IOException {DataInputStream in = new DataInputStream (new BufferedInputStream (new FileInputStream (path1); byte [] B = new byte [in. available ()]; // available returns the actual number of readable bytes, that is, the total size in. read (B); DataOutputStream out = new DataOutputStream (new BufferedOutputStream (new FileOutputStream (path2); out. write (B); in. close (); out. close () ;}// main method public static void main (String [] args) {FileCopyAndDelete f = new FileCopyAndDelete (); // test copy files using recursive/** {String path1 = "D: // Folder1"; String path2 = "D: // Folder2"; try {* f. copyFiles (path1, path2); System. out. println ("OK, COPY FINISH");} * catch (IOException e) {e. printStackTrace () ;}} * // test delete files using recursive/** {f. deleteFile ("C: // Folder1"); * System. out. println ("OK, DELETE FINISH ");}*/}}