[JAVA] File copy and paste function / FileUtils.copyFile(file, newFile);

  1. Download the library
    Commons IO – Download Apache Commons IO

  2. Create a folder called ‘code’ in your ‘Sketch folder’.

  3. After that, put the downloaded file in the ‘code’ file.

  4. Source Code

import java.io.File;
import java.io.IOException; 
import org.apache.commons.io.FileUtils;

void setup(){
  size(500,500);
  

  try {
      String url1 = dataPath("")+"/test.txt";
      String url2 = "C://Users\\user\\Desktop/test.txt";
      File files   = new File(url1);
      File newFile = new File(url2);      
      FileUtils.copyFile(files, newFile);
  }
  catch (Exception e) {
    println("Error in saving the file...sorry!");
  }

}