public class FileUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
copyFile(File sourceFile,
File targetFile)
Copies a single file to a target destination and logs any errors.
|
static boolean |
createDirectories(File directory)
Attempts to create all directories of a given directory path.
|
static void |
createEmptyFile(File file)
Creates a new cache file, replacing any file that already exists.
|
static void |
deleteFile(File deletedFile)
Attempts to delete a file from disk if it exists and logs any errors.
|
static BufferedReader |
getReader(File file,
Charset charset)
Opens an InputStream to a specified file and wraps it in a
BufferedReader using a specified Charset.
|
static BufferedReader |
getReader(String filePath,
Charset charset)
Opens an InputStream to a specified file and wraps it in a
BufferedReader using a specified Charset.
|
static BufferedWriter |
getWriter(File file,
Charset charset)
Opens an OutputStream to a specified file and wraps it in a
BufferedWriter using a specified Charset.
|
static BufferedWriter |
getWriter(String filePath,
Charset charset)
Opens an OutputStream to a specified file and wraps it in a
BufferedWriter using a specified Charset.
|
static void |
integrateDirectory(File sourceDirectory,
File targetDirectory,
boolean replaceFiles)
Merges one directory into another one.
|
static void |
replaceFile(File targetFile,
File newFile)
Replaces one file with another and logs any errors.
|
public static void deleteFile(File deletedFile)
deletedFile - the file that is to be deletedpublic static void replaceFile(File targetFile, File newFile)
targetFile - the file that is to be replacednewFile - the new file that replaces the target filepublic static void copyFile(File sourceFile, File targetFile)
sourceFile - the file that is to be copiedtargetFile - the destination filepublic static boolean createDirectories(File directory)
directory - the directory path to be createdpublic static void createEmptyFile(File file)
file - the file that is to be createdpublic static void integrateDirectory(File sourceDirectory, File targetDirectory, boolean replaceFiles)
sourceDirectory - the directory that is to be integratedtargetDirectory - the directory into which the other folder is mergedreplaceFiles - if true, sourceDirectory files with the same name as in the
target directory, will be replacedpublic static BufferedReader getReader(String filePath, Charset charset) throws IOException
filePath - the path to the file that is to be readcharset - the charset used to parse the fileIOException - if the file cannot be readpublic static BufferedReader getReader(File file, Charset charset) throws IOException
file - the file that is to be readcharset - the charset used to parse the fileIOException - if the file cannot be readpublic static BufferedWriter getWriter(String filePath, Charset charset) throws IOException
filePath - the path to the file that is to be written tocharset - the charset used to write to the fileIOException - if the file cannot be read or written topublic static BufferedWriter getWriter(File file, Charset charset) throws IOException
file - the file that is to be written tocharset - the charset used to write to the fileIOException - if the file cannot be read or written toCopyright © 2017–2019. All rights reserved.