public class TempFile extends Object
Utility methods to work with temporary files and directories.
| Constructor and Description |
|---|
TempFile() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
deleteAfter(File file,
FunctionWithException<File,T> f)
Apply
f to the given file file and delete the file after the function
returns. |
static boolean |
deleteRecursive(File file)
Delete a file recursively.
|
static String |
readFile(File file)
Reads the given text file and return it’s contents.
|
static <T> T |
withTempDir(FunctionWithException<File,T> f)
Apply
f to a newly created temporary directory which is deleted after
f returns. |
static void |
withTempDirP(ProcedureWithException<File> p)
Apply
p to a newly created temporary directory which is deleted after
p returns. |
static <T> T |
withTempFile(String content,
FunctionWithException<File,T> f)
Creates a new temporary file with the given content
content. |
static void |
withTempFileP(String content,
ProcedureWithException<File> p)
Creates a new temporary file with the given content
content. |
static void |
writeToFile(File file,
String content) |
public static <T> T withTempDir(FunctionWithException<File,T> f) throws Exception
Apply f to a newly created temporary directory which is deleted after
f returns.
Exceptionpublic static void withTempDirP(ProcedureWithException<File> p) throws Exception
Apply p to a newly created temporary directory which is deleted after
p returns.
This is the procedural equivalent of
withTempDir(FunctionWithException).
Exceptionpublic static <T> T withTempFile(String content, FunctionWithException<File,T> f) throws Exception
Creates a new temporary file with the given content content. After
execution of the given function f the file is deleted.
Exceptionpublic static void withTempFileP(String content, ProcedureWithException<File> p) throws Exception
Creates a new temporary file with the given content content. After
execution of the given procedure p the file is deleted.
This is the procedural equivalent of
withTempFile(String, FunctionWithException).
Exceptionpublic static void writeToFile(File file, String content) throws IOException
IOExceptionpublic static String readFile(File file) throws IOException
Reads the given text file and return it’s contents.
file - The text file.IOException - In case the file is missing or can’t be read as text.public static <T> T deleteAfter(File file, FunctionWithException<File,T> f) throws Exception
Apply f to the given file file and delete the file after the function
returns.
Exceptionpublic static boolean deleteRecursive(File file)
Delete a file recursively.
true if the deletion was successful.Copyright © 2019. All rights reserved.