Java Temporary Files and Directories: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Java =Overview=")
 
(7 intermediate revisions by the same user not shown)
Line 3: Line 3:
* [[Java#Subjects|Java]]
* [[Java#Subjects|Java]]


=Overview=
=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|default temporary-file directory]]:
<syntaxhighlight lang='java'>
java.nio.file.Files.createTempDirectory(Path dir, String prefix, FileAttribute<?>... attrs);
java.nio.file.Files.createTempDirectory(String prefix, FileAttribute<?>... attrs);
</syntaxhighlight>
 
On a Mac,
 
<syntaxhighlight lang='java'>
Files.createTempDirectory("test");
</syntaxhighlight>
 
creates /var/folders/t3/mmn20npx7fs31lwlp2s4_6wm0000gq/T/test5357804169564764079.
 
The directory is not automatically deleted upon the VM exit.
 
=Temporary File=
 
<syntaxhighlight lang='java'>
</syntaxhighlight>

Revision as of 20:25, 11 February 2020

Internal

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