public final class TempFile extends Object implements Scalar<Path>, Closeable
These are ephemeral files to be used in small scopes. Typical use looks like this:
try (final TempFile file = new TempFile()) {
//write to the file
}
The physical file is deleted from the filesystem when the temp file is
closed.Constructor and Description |
---|
TempFile()
Ctor.
|
TempFile(Scalar<Path> dir,
String prefix,
String suffix)
Ctor.
|
TempFile(Scalar<Path> dir,
Text prefix,
Text suffix)
Ctor.
|
TempFile(String prefix,
String suffix)
Ctor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Deletes the file from the filesystem.
|
Path |
value()
Convert it to the value.
|
public TempFile()
Specifies empty strings for suffix and prefix, and creates the file
in the filesystem's temporary directory denoted by the system property
java.io.tmpdir
.
public TempFile(String prefix, String suffix)
The temporary file will be created inside the filesystem's
temporary folder (system property: java.io.tmpdir
).
prefix
- The temp filename's prefixsuffix
- The temp filename's suffixpublic TempFile(Scalar<Path> dir, String prefix, String suffix)
dir
- The directory in which to create the temp fileprefix
- The temp filename's prefixsuffix
- The temp filename's suffixpublic Path value() throws Exception
Scalar
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2017–2021 Cactoos. All rights reserved.