Control temporary files

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Comparison MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-comparison -- dnx GroupDocs.Comparison.Mcp --yes
Folders, licensing and more →

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