|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.qpid.util.FileUtils
public class FileUtils
FileUtils provides some simple helper methods for working with files. It follows the convention of wrapping all checked exceptions as runtimes, so code using these methods is free of try-catch blocks but does not expect to recover from errors.
Responsibilities | Collaborations |
---|---|
Read a text file as a string. | |
Open a file or default resource as an input stream. |
Nested Class Summary | |
---|---|
static class |
FileUtils.UnableToCopyException
|
Constructor Summary | |
---|---|
FileUtils()
|
Method Summary | |
---|---|
static void |
copy(File src,
File dst)
Copies the specified source file to the specified destintaion 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 uses the default resource loaded using the specified class loader, if opening the file fails or no file name is specified. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileUtils()
Method Detail |
---|
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
public 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
FileNotFoundException
FileUtils.UnableToCopyException
public static List<String> searchFile(File file, String search) throws IOException
file
- the file to searchsearch
- the search String
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |