public class FileUtils
extends java.lang.Object
Set of methods to help and ease the manipulation of Files. Most likely adding minor behavior on top of existing Files methods.
Methods in that file are static so no instance of FileUtils is necessary.
| Constructor and Description |
|---|
FileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
copy(java.nio.file.Path fromFile,
java.nio.file.Path toFile) |
static java.lang.String |
silentRead(java.nio.file.Path file)
Reads the file located at the specified Path, and returns its content in case the file exists.
|
static void |
silentRemove(java.nio.file.Path file)
Removes the file located at the specified Path if it exists.
|
static void |
silentRemoveRec(java.io.File file)
Removes recursively all elements if
file is a directory, then removes file. |
static void |
write(java.lang.String content,
java.nio.file.Path file)
Writes the specified
content in the file located at the specified Path. |
public static java.lang.String silentRead(java.nio.file.Path file)
Reads the file located at the specified Path, and returns its content in case the file exists.
If it doesn’t exist or if it cannot be read, that method will return an empty String and ignore the IOException. An error message will be written in System.err though.
file - The path of the file to be readpublic static void silentRemove(java.nio.file.Path file)
Removes the file located at the specified Path if it exists.
If the file doesn’t exist, nothing will be done.
If the file exists but cannot be removed, an error will simply be written in System.err and the Exception won’t be propagated (since it doesn’t block the framework from working properly). We strongly advise to have a look at the problem though.
file - The path of the file to be removedpublic static void silentRemoveRec(java.io.File file)
Removes recursively all elements if file is a directory, then removes file.
If the file doesn’t exist, nothing will be done.
file - the file to be removedpublic static void write(java.lang.String content,
java.nio.file.Path file)
Writes the specified content in the file located at the specified Path.
If the directories supposed to contain the specified file don’t exist, they’ll be created by this method automatically. A message will be written in System.err and a RuntimeException will be thrown in case of any error.
The provided content will then be written in the provided file. A RuntimeException will be thrown in case anything is going wrong will writing the content in the file.
content - The content to be written in the specified filefile - The file in which the content should be writtenpublic static void copy(java.nio.file.Path fromFile,
java.nio.file.Path toFile)
Copyright © 2018 Write Them First!. All rights reserved.