public class Files
extends java.lang.Object
Modifier | Constructor and Description |
---|---|
private |
Files() |
Modifier and Type | Method and Description |
---|---|
private static RuntimeIOException |
cannotCreateNewFile(java.lang.String path,
java.lang.Exception cause) |
private static RuntimeIOException |
cannotCreateNewFile(java.lang.String path,
java.lang.String reason) |
private static RuntimeIOException |
cannotCreateNewFile(java.lang.String path,
java.lang.String reason,
java.lang.Exception cause) |
static java.lang.String |
contentOf(java.io.File file,
java.nio.charset.Charset charset)
Loads the text content of a file into a character string.
|
static java.lang.String |
contentOf(java.io.File file,
java.lang.String charsetName)
Loads the text content of a file into a character string.
|
private static java.io.File |
createFileIfPathIsNotANonEmptyDirectory(java.lang.String path) |
static java.io.File |
currentFolder()
Returns the current directory.
|
static void |
delete(java.io.File file)
Deletes the given file or directory.
|
private static java.util.List<java.lang.String> |
fileNamesIn(java.io.File dir,
boolean recurse)
Returns the names of the files inside the specified directory.
|
static java.util.List<java.lang.String> |
fileNamesIn(java.lang.String dirName,
boolean recurse)
Returns the names of the files inside the specified directory.
|
static java.util.List<java.lang.String> |
linesOf(java.io.File file,
java.nio.charset.Charset charset)
Loads the text content of a file into a list of strings, each string corresponding to a line.
|
static java.util.List<java.lang.String> |
linesOf(java.io.File file,
java.lang.String charsetName)
Loads the text content of a file into a list of strings, each string corresponding to a line.
|
private static java.lang.String |
loadContents(java.io.File file,
java.nio.charset.Charset charset) |
private static java.util.List<java.lang.String> |
loadLines(java.io.File file,
java.nio.charset.Charset charset) |
static java.io.File |
newFile(java.lang.String path)
Creates a new file using the given path.
|
static java.io.File |
newFolder(java.lang.String path)
Creates a new directory using the given path.
|
static java.io.File |
newTemporaryFile()
Creates a new file in the system's temporary directory.
|
static java.io.File |
newTemporaryFolder()
Creates a new directory in the system's temporary directory.
|
static java.io.File |
temporaryFolder()
Returns the system's temporary directory.
|
static java.lang.String |
temporaryFolderPath()
Returns the path of the system's temporary directory.
|
public static java.util.List<java.lang.String> fileNamesIn(java.lang.String dirName, boolean recurse)
dirName
- the name of the directory to start the search from.recurse
- if true
, we will look in subdirectories.java.lang.IllegalArgumentException
- if the given directory name does not point to an existing directory.private static java.util.List<java.lang.String> fileNamesIn(java.io.File dir, boolean recurse)
dir
- the name of the directory to start the search from.recurse
- if true
, we will look in subdirectories.public static java.io.File temporaryFolder()
RuntimeIOException
- if this method cannot find or create the system's temporary directory.public static java.lang.String temporaryFolderPath()
public static java.io.File newTemporaryFile()
concat(String.valueOf(System.currentTimeMillis()), ".txt");
public static java.io.File newTemporaryFolder()
System.currentTimeMillis();
public static java.io.File newFile(java.lang.String path)
path
- the path of the new file.RuntimeIOException
- if the path belongs to an existing non-empty directory.RuntimeIOException
- if the path belongs to an existing file.RuntimeIOException
- if any I/O error is thrown when creating the new file.public static java.io.File newFolder(java.lang.String path)
path
- the path of the new directory.RuntimeIOException
- if the path belongs to an existing non-empty directory.RuntimeIOException
- if the path belongs to an existing file.RuntimeIOException
- if any I/O error is thrown when creating the new directory.private static java.io.File createFileIfPathIsNotANonEmptyDirectory(java.lang.String path)
private static RuntimeIOException cannotCreateNewFile(java.lang.String path, java.lang.String reason)
private static RuntimeIOException cannotCreateNewFile(java.lang.String path, java.lang.Exception cause)
private static RuntimeIOException cannotCreateNewFile(java.lang.String path, java.lang.String reason, java.lang.Exception cause)
public static java.io.File currentFolder()
RuntimeIOException
- if the current directory cannot be obtained.public static void delete(java.io.File file)
file
- the file or directory to delete.public static java.lang.String contentOf(java.io.File file, java.lang.String charsetName)
file
- the file.charsetName
- the name of the character set to use.java.lang.IllegalArgumentException
- if the given character set is not supported on this platform.RuntimeIOException
- if an I/O exception occurs.public static java.lang.String contentOf(java.io.File file, java.nio.charset.Charset charset)
file
- the file.charset
- the character set to use.java.lang.NullPointerException
- if the given charset is null
.RuntimeIOException
- if an I/O exception occurs.private static java.lang.String loadContents(java.io.File file, java.nio.charset.Charset charset) throws java.io.IOException
java.io.IOException
public static java.util.List<java.lang.String> linesOf(java.io.File file, java.nio.charset.Charset charset)
file
- the file.charset
- the character set to use.java.lang.NullPointerException
- if the given charset is null
.RuntimeIOException
- if an I/O exception occurs.public static java.util.List<java.lang.String> linesOf(java.io.File file, java.lang.String charsetName)
file
- the file.charsetName
- the name of the character set to use.java.lang.NullPointerException
- if the given charset is null
.RuntimeIOException
- if an I/O exception occurs.private static java.util.List<java.lang.String> loadLines(java.io.File file, java.nio.charset.Charset charset) throws java.io.IOException
java.io.IOException