public class FileUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
FileUtils.UnableToCopyException |
Modifier and Type | Method and Description |
---|---|
static void |
copy(File src,
File dst)
Copies the specified source file to the specified destintaion file.
|
static void |
copy(InputStream in,
File dst)
Copies the specified InputStream to the specified destination file.
|
static void |
copyCheckedEx(File src,
File dst)
Copies the specified source file to the specified destination file.
|
static void |
copyRecursive(File source,
File dst) |
static boolean |
delete(File file,
boolean recursive)
Delete a given file/directory,
A directory will always require the recursive flag to be set.
|
static boolean |
deleteDirectory(String directoryPath) |
static boolean |
deleteFile(String filePath) |
static InputStream |
openFileOrDefaultResource(String filename,
String defaultResource,
ClassLoader cl)
Either opens the specified filename as an input stream or either the filesystem or classpath,
or uses the default resource loaded using the specified class loader, if opening the file fails
or no file name is specified.
|
static byte[] |
readFileAsBytes(String filename)
Reads a text file as a string.
|
static String |
readFileAsString(File file)
Reads a text file as a string.
|
static String |
readFileAsString(String filename)
Reads a text file as a string.
|
static List<String> |
searchFile(File file,
String search)
Checks the specified file for instances of the search string.
|
public static byte[] readFileAsBytes(String filename)
filename
- The name of the file.public static String readFileAsString(String filename)
filename
- The name of the file.public static String readFileAsString(File file)
file
- The file.public static InputStream openFileOrDefaultResource(String filename, String defaultResource, ClassLoader cl)
filename
- The name of the file to open.defaultResource
- The name of the default resource on the classpath if the file cannot be opened.cl
- The classloader to load the default resource with.public static void copy(File src, File dst)
src
- The source file name.dst
- The destination file name.public static void copyCheckedEx(File src, File dst) throws IOException
src
- The source file name.dst
- The destination file name.IOException
- if there is an issue copying the filepublic static void copy(InputStream in, File dst) throws IOException
in
- The InputStreamdst
- The destination file name.IOException
- if there is an issue copying the streampublic static boolean deleteFile(String filePath)
public static boolean deleteDirectory(String directoryPath)
public static boolean delete(File file, boolean recursive)
file
- the File object to start atrecursive
- boolean to recurse if a directory is specified.true
if and only if the file or directory is
successfully deleted; false
otherwisepublic static void copyRecursive(File source, File dst) throws FileNotFoundException, FileUtils.UnableToCopyException
public static List<String> searchFile(File file, String search) throws IOException
file
- the file to searchsearch
- the search StringIOException
- if there is an issue searching the fileCopyright © 2006–2016 The Apache Software Foundation. All rights reserved.