public final class FileUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
copyDirectory(@NonNull File srcDir,
@NonNull File destDir,
CopyOption... options)
Copies a directory recursively, preserving the files last modified date.
|
static void |
copyFile(@NonNull File srcFile,
@NonNull File destFile,
CopyOption... options)
Copies a file to another path, preserving the last modified date.
|
static void |
copyFileToDirectory(@NonNull File srcFile,
@NonNull File destDir,
CopyOption... options)
Copies a file to a directory, preserving the last modified date.
|
static boolean |
delete(@Nullable File file)
Deletes a file.
|
static boolean |
deleteQuietly(@Nullable File file)
Deletes a file, never throwing an exception.
|
static @Nullable String |
getBaseName(@Nullable String filename)
Gets the name minus the path and extension from a full filename.
|
static @Nullable String |
getExtension(@Nullable String filename)
Gets the file extension from a full filename.
|
static @Nullable String |
getName(@Nullable String filename)
Gets the name minus the path from a full filename.
|
static @NonNull String |
readFileToString(@NonNull File file,
@NonNull Charset encoding)
Reads the contents of a file into a String.
|
public static void copyFile(@NonNull File srcFile, @NonNull File destFile, CopyOption... options) throws IOException
srcFile - An existing file to copy, must not be null.destFile - The target file, must not be null.options - Options specifying how the copy should be done.IOException - If an IO error occurs.public static void copyFileToDirectory(@NonNull File srcFile, @NonNull File destDir, CopyOption... options) throws IOException
srcFile - An existing file to copy, must not be null.destDir - The directory to place the copy in, must not be null.options - Options specifying how the copy should be done.IOException - If an IO error occurs.public static void copyDirectory(@NonNull File srcDir, @NonNull File destDir, CopyOption... options) throws IOException
srcDir - An existing directory to copy, must not be null.destDir - The target directory, must not be null.options - Options specifying how the copy should be done.IOException - If an IO error occurs.public static boolean delete(@Nullable File file) throws IOException
file - File or directory to delete, can be null.true If the file or directory was deleted, false otherwise. The file or
directory is considered deleted if it exists entering the function and if it does not exist
when the function ends, meaning that a null input file or a file that does not
exist will return false.IOException - If an IO error occurs.public static boolean deleteQuietly(@Nullable File file)
file - File or directory to delete, can be null.true If the file or directory is deleted, false otherwise.public static @Nullable String getBaseName(@Nullable String filename)
filename - The filename to query, may be null.public static @Nullable String getExtension(@Nullable String filename)
filename - The filename to query, may be null.public static @Nullable String getName(@Nullable String filename)
filename - The filename to query, may be null.public static @NonNull String readFileToString(@NonNull File file, @NonNull Charset encoding) throws IOException
file - The file to read, must not be null.encoding - The encoding to use, must not be null.null.IOException - If an IO error occurs.Copyright © 2016 - present; JODConverter.org. All rights reserved.