Package org.cactoos.io
Class TempFile
- java.lang.Object
-
- org.cactoos.io.TempFile
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Scalar<Path>
public final class TempFile extends Object implements Scalar<Path>, Closeable
A temporary file.These are ephemeral files to be used in small scopes. Typical use looks like this:
The physical file is deleted from the filesystem when the temp file is closed.try (final TempFile file = new TempFile()) { //write to the file }
- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Deletes the file from the filesystem.Path
value()
Convert it to the value.
-
-
-
Constructor Detail
-
TempFile
public TempFile()
Ctor.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
.- Since:
- 1.0
-
TempFile
public TempFile(String prefix, String suffix)
Ctor.The temporary file will be created inside the filesystem's temporary folder (system property:
java.io.tmpdir
).- Parameters:
prefix
- The temp filename's prefixsuffix
- The temp filename's suffix- Since:
- 1.0
-
TempFile
public TempFile(Text prefix, Text suffix)
Ctor.The temporary file will be created inside the filesystem's temporary folder (system property:
java.io.tmpdir
).- Parameters:
prefix
- The temp filename's prefixsuffix
- The temp filename's suffix- Since:
- 1.0
-
TempFile
public TempFile(Scalar<Path> dir, String prefix, String suffix)
Ctor.- Parameters:
dir
- The directory in which to create the temp fileprefix
- The temp filename's prefixsuffix
- The temp filename's suffix- Since:
- 1.0
-
-
Method Detail
-
value
public Path value() throws Exception
Description copied from interface:Scalar
Convert it to the value.
-
close
public void close() throws IOException
Deletes the file from the filesystem.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-