Java Temporary Files and Directories

From NovaOrdis Knowledge Base
Revision as of 21:19, 17 February 2022 by Ovidiu (talk | contribs) (→‎Internal)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Internal

TODO

Default Temporary-File Directory

The JVM obtains the default temp directory from the "java.io.tmpdir" property.

Temporary Directory

Java can create a temporary directory in a given directory or in the default temporary-file directory:

java.nio.file.Files.createTempDirectory(Path dir, String prefix, FileAttribute<?>... attrs);
java.nio.file.Files.createTempDirectory(String prefix, FileAttribute<?>... attrs);

On a Mac,

Files.createTempDirectory("test");

creates /var/folders/t3/mmn20npx7fs31lwlp2s4_6wm0000gq/T/test5357804169564764079.

The directory is not automatically deleted upon the VM exit.

Temporary File