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

**URL:** <https://discourse.processing.org/t/java-file-copy-and-paste-function-fileutils-copyfile-file-newfile/39683>\
**Category:** Gallery\
**Created:** [November 13, 2022, 3:56am UTC](https://discourse.processing.org/t/java-file-copy-and-paste-function-fileutils-copyfile-file-newfile/39683 "2022-11-13T03:56:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [November 13, 2022, 3:56am UTC](https://discourse.processing.org/t/java-file-copy-and-paste-function-fileutils-copyfile-file-newfile/39683/1 "2022-11-13T03:56:51Z")

</div>

1. Download the library  
[Commons IO – Download Apache Commons IO](https://commons.apache.org/proper/commons-io/download_io.cgi)

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

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

4. Source Code

```auto
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!");
  }

}

```
