IOUtils copyLarge method

In this post under Apache Commons IO, I will show with example the purpose of static method “copyLarge” available in “IOUtils” class.

In our previous post under Apache Commons IO, we already covered “copy” method available in “IOUtils” class.

The purpose of both the methods is same i.e., copy the contents of one file into another.

The difference being the size of source file, the method supports.

The “copy” method cannot copy large files i.e., more than 2GB. That is where “copyLarge” method comes into picture.

The “copyLarge” method works for files with size more than 2GB.

Below is the main class for your reference

Main class

package ioutils;

import org.apache.commons.io.IOUtils;

import java.io.*;

public class Example13 {
    public static void main(String[] args) throws IOException {
        File sourceFile = new File("Example.pdf");
        File destinationFile = new File("ExampleCopy.pdf");

        try(FileInputStream fileInputStream = new FileInputStream(sourceFile);
            FileOutputStream fileOutputStream = new FileOutputStream(destinationFile)) {
            IOUtils.copyLarge(fileInputStream, fileOutputStream);
        }
    }
}

In this way, we can use “copyLarge” method.

Leave a comment