Control temporary files

On this page

GroupDocs.Comparison allows you to manage temporary files and directories. To do this, follow these steps:

  1. Create a class that implements the com.groupdocs.comparison.common.tempfiles.TemporaryFileManager interface and its methods:
class CustomTemporaryFileManager implements TemporaryFileManager {

    @Override
    public Path createTempDirectory() {
        // Implementation
    }

    @Override
    public Path createTempDirectory(String... pathsAsStrings) {
        // Implementation
    }

    @Override
    public Path createTempDirectory(Path... paths) {
        // Implementation
    }

    @Override
    public Path createTempFile() {
        // Implementation
    }

    @Override
    public Path createTempFile(String... pathsAsStrings) {
        // Implementation
    }

    @Override
    public Path createTempFile(Path... paths) {
        // Implementation
    }

    @Override
    public void delete(Path path) {
        // Implementation
    }

    @Override
    public void cleanup() {
        // Implementation
    }
}
  1. Create an object of this class and pass it to the setInstance method of TemporaryFileManagerFactory:
final CustomTemporaryFileManager customTemporaryFileManager = new CustomTemporaryFileManager();
TemporaryFileManagerFactory.setInstance(customTemporaryFileManager);

Now GroupDocs.Comparison uses the implementation for creating temporary files and directories.

  1. Use it in the next way:
final TemporaryFileManager temporaryFileManager = TemporaryFileManagerFactory.getInstance();
final Path tempFile = temporaryFileManager.createTempFile("temp.txt");
// Do something with the file
temporaryFileManager.delete(tempFile);
Note
Default implementation creates temporary files and directories in a directory specified by java.io.tmpdir property.

On this page