Java Temporary Files and Directories: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Java =Overview=")
 
 
(10 intermediate revisions by the same user not shown)
Line 2: Line 2:


* [[Java#Subjects|Java]]
* [[Java#Subjects|Java]]
* [[NIO 2 File API]]
* [[Temporary Files and Directories]]


=Overview=
=TODO=
 
* https://blogs.oracle.com/javamagazine/working-and-unit-testing-with-temporary-files-in-java
 
=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>

Latest revision as of 21:19, 17 February 2022

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