Package org.assertj.core.util
Class Files
java.lang.Object
org.assertj.core.util.Files
Utility methods related to files.
- Author:
- Yvonne Wang, Alex Ruiz
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Loads the text content of a file into a character string.static String
Loads the text content of a file into a character string.static File
Returns the current directory.static void
Deprecated.use https://commons.apache.org/proper/commons-io/javadocs/api-release/org/apache/commons/io/FileUtils.html#forceDelete-java.io.File- insteadfileNamesIn
(String dirName, boolean recurse) Returns the names of the files inside the specified directory.getFileNameExtension
(String fileName) Loads the text content of a file into a list of strings, each string corresponding to a line.Loads the text content of a file into a list of strings, each string corresponding to a line.static File
Creates a new file using the given path.static File
Creates a new directory using the given path.static File
Creates a new file in the system's temporary directory.static File
Creates a new directory in the system's temporary directory.static File
Deprecated.Use eitherTempDir
orTemporaryFolder
static String
Returns the path of the system's temporary directory.
-
Method Details
-
fileNamesIn
Returns the names of the files inside the specified directory.- Parameters:
dirName
- the name of the directory to start the search from.recurse
- iftrue
, we will look in subdirectories.- Returns:
- the names of the files inside the specified directory.
- Throws:
IllegalArgumentException
- if the given directory name does not point to an existing directory.
-
temporaryFolder
Deprecated.Use eitherTempDir
orTemporaryFolder
Returns the system's temporary directory.- Returns:
- the system's temporary directory.
- Throws:
RuntimeException
- if this method cannot find or create the system's temporary directory.
-
temporaryFolderPath
Returns the path of the system's temporary directory. This method appends the system's file separator at the end of the path.- Returns:
- the path of the system's temporary directory.
-
newTemporaryFile
Creates a new file in the system's temporary directory. The name of the file will be the result of:concat(UUID.randomUUID().toString(), ".txt");
- Returns:
- the created file.
-
newTemporaryFolder
Creates a new directory in the system's temporary directory. The name of the directory will be the result of:UUID.randomUUID().toString();
- Returns:
- the created file.
-
newFile
Creates a new file using the given path.- Parameters:
path
- the path of the new file.- Returns:
- the new created file.
- Throws:
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.
-
newFolder
Creates a new directory using the given path.- Parameters:
path
- the path of the new directory.- Returns:
- the new created directory.
- Throws:
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.
-
currentFolder
Returns the current directory.- Returns:
- the current directory.
- Throws:
UncheckedIOException
- if the current directory cannot be obtained.
-
delete
Deprecated.use https://commons.apache.org/proper/commons-io/javadocs/api-release/org/apache/commons/io/FileUtils.html#forceDelete-java.io.File- insteadDeletes the given file or directory.- Parameters:
file
- the file or directory to delete.
-
contentOf
Loads the text content of a file into a character string.- Parameters:
file
- the file.charsetName
- the name of the character set to use.- Returns:
- the content of the file.
- Throws:
IllegalArgumentException
- if the given character set is not supported on this platform.UncheckedIOException
- if an I/O exception occurs.
-
contentOf
Loads the text content of a file into a character string.- Parameters:
file
- the file.charset
- the character set to use.- Returns:
- the content of the file.
- Throws:
NullPointerException
- if the given charset isnull
.UncheckedIOException
- if an I/O exception occurs.
-
linesOf
Loads the text content of a file into a list of strings, each string corresponding to a line. The line endings are either \n, \r or \r\n.- Parameters:
file
- the file.charset
- the character set to use.- Returns:
- the content of the file.
- Throws:
NullPointerException
- if the given charset isnull
.UncheckedIOException
- if an I/O exception occurs.
-
linesOf
Loads the text content of a file into a list of strings, each string corresponding to a line. The line endings are either \n, \r or \r\n.- Parameters:
file
- the file.charsetName
- the name of the character set to use.- Returns:
- the content of the file.
- Throws:
NullPointerException
- if the given charset isnull
.UncheckedIOException
- if an I/O exception occurs.
-
getFileNameExtension
-