public class Files extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
contentOf(File file,
Charset charset)
Loads the text content of a file into a character string.
|
static String |
contentOf(File file,
String charsetName)
Loads the text content of a file into a character string.
|
static File |
currentFolder()
Returns the current directory.
|
static void |
delete(File file)
Deletes the given file or directory.
|
static List<String> |
fileNamesIn(String dirName,
boolean recurse)
Returns the names of the files inside the specified directory.
|
static List<String> |
linesOf(File file,
Charset charset)
Loads the text content of a file into a list of strings, each string corresponding to a line.
|
static List<String> |
linesOf(File file,
String charsetName)
Loads the text content of a file into a list of strings, each string corresponding to a line.
|
static File |
newFile(String path)
Creates a new file using the given path.
|
static File |
newFolder(String path)
Creates a new directory using the given path.
|
static File |
newTemporaryFile()
Creates a new file in the system's temporary directory.
|
static File |
newTemporaryFolder()
Creates a new directory in the system's temporary directory.
|
static File |
temporaryFolder()
Returns the system's temporary directory.
|
static String |
temporaryFolderPath()
Returns the path of the system's temporary directory.
|
public static List<String> fileNamesIn(String dirName, boolean recurse)
dirName - the name of the directory to start the search from.recurse - if true, we will look in subdirectories.IllegalArgumentException - if the given directory name does not point to an existing directory.public static File temporaryFolder()
RuntimeException - if this method cannot find or create the system's temporary directory.public static String temporaryFolderPath()
public static File newTemporaryFile()
concat(UUID.randomUUID().toString(), ".txt");public static File newTemporaryFolder()
UUID.randomUUID().toString();public static File newFile(String path)
path - the path of the new file.RuntimeException - if the path belongs to an existing non-empty directory.RuntimeException - if the path belongs to an existing file.UncheckedIOException - if any I/O error is thrown when creating the new file.public static File newFolder(String path)
path - the path of the new directory.RuntimeException - if the path belongs to an existing non-empty directory.RuntimeException - if the path belongs to an existing file.RuntimeException - if any I/O error is thrown when creating the new directory.public static File currentFolder()
UncheckedIOException - if the current directory cannot be obtained.public static void delete(File file)
file - the file or directory to delete.public static String contentOf(File file, String charsetName)
file - the file.charsetName - the name of the character set to use.IllegalArgumentException - if the given character set is not supported on this platform.UncheckedIOException - if an I/O exception occurs.public static String contentOf(File file, Charset charset)
file - the file.charset - the character set to use.NullPointerException - if the given charset is null.UncheckedIOException - if an I/O exception occurs.public static List<String> linesOf(File file, Charset charset)
file - the file.charset - the character set to use.NullPointerException - if the given charset is null.UncheckedIOException - if an I/O exception occurs.public static List<String> linesOf(File file, String charsetName)
file - the file.charsetName - the name of the character set to use.NullPointerException - if the given charset is null.UncheckedIOException - if an I/O exception occurs.Copyright © 2014–2019 AssertJ. All rights reserved.