|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.uima.util.FileUtils
public class FileUtils
Some utilities for handling files.
Constructor Summary | |
---|---|
FileUtils()
|
Method Summary | |
---|---|
static void |
copyFile(File file,
File dir)
Copy file file to location dir . |
static File |
createTempDir(File parent,
String prefix)
Create a temporary directory using random numbers as name suffixes. |
static File |
createTempFile(String prefix,
String suffix,
File tempDir)
|
static void |
deleteAllFiles(File directory)
Delete all files in a directory (not recursive). |
static boolean |
deleteRecursive(File file)
Recursively delete possibly non-empty directory or file. |
static String |
file2String(File file)
Read the contents of a file into a string, using the default platform encoding. |
static String |
file2String(File file,
String fileEncoding)
Read the contents of a file into a string using a specific character encoding. |
static String |
findRelativePath(File file,
File relativeToDir)
Finds a relative path to a given file, relative to a specified directory. |
static ArrayList<File> |
getFiles(File directory)
Get a list of all files in a directory, ignoring subdirectories. |
static ArrayList<File> |
getFiles(File directory,
boolean getRecursive)
Get a list of all files in a directory. |
static String[] |
getPathComponents(String canonicalPath)
Splits a path into components using the OS file separator character. |
static ArrayList<File> |
getSubDirs(File directory)
Get a list of all subdirectories in a directory, ignoring regular files. |
static boolean |
mkdir(File directory)
Create a new directory. |
static String |
reader2String(Reader reader)
Read a bufferedReader into a string, using the default platform encoding. |
static void |
saveString2File(String fileContents,
File file)
Write a string to a file, using platform encoding. |
static void |
saveString2File(String s,
File file,
String encoding)
Write a string to a file using the specified encoding. |
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 final ArrayList<File> getFiles(File directory, boolean getRecursive)
directory
- The directory for which to get the files.getRecursive
- Should we get files from subdirectories?
File
objects. null
if
directory
does not exist, or is not a directory.public static final ArrayList<File> getFiles(File directory)
directory
- The directory for which to get the files.
File
objects. null
if
directory
does not exist, or is not a directory.public static final ArrayList<File> getSubDirs(File directory)
directory
- The directory for which to get the subdirectories.
File
objects. null
if
directory
does not exist, or is not a directory.public static String reader2String(Reader reader) throws IOException
reader
- to be read in
IOException
- Various I/O errors.public static String file2String(File file) throws IOException
file
- The file to be read in.
IOException
- Various I/O errors.public static String file2String(File file, String fileEncoding) throws IOException
file
- The input file.fileEncoding
- The character encoding of the file (see your Java documentation for supported
encodings).
IOException
- Various I/O errors.public static void saveString2File(String fileContents, File file) throws IOException
fileContents
- The file contents.file
- The file to save to.
IOException
- If for any reason the file can't be written.public static void saveString2File(String s, File file, String encoding) throws IOException
s
- The file contents.file
- The file to save to.encoding
- The character encoding to use.
IOException
- If for any reason the file can't be written.public static final void deleteAllFiles(File directory)
directory
- The directory that contains the files to be deleted.public static final boolean deleteRecursive(File file)
file
- The file or directory to be deleted.
true
iff the file/directory could be deleted.public static final boolean mkdir(File directory)
directory
- The directory to be created.
false
.public static final File createTempDir(File parent, String prefix)
parent
- Where the directory is created.prefix
- Prefix of the directory names to be created.
null
if none
could be created for some reason (e.g., if the parent is not writable).public static final File createTempFile(String prefix, String suffix, File tempDir) throws IOException
IOException
public static final void copyFile(File file, File dir) throws IOException
file
to location dir
. This method will not fail silently.
Anything that prevents the copy from happening will be treated as an error condition. If the
method does not throw an exception, the copy was successful.
Note: this is a completely brain-dead implementation of file copy. The complete file is read into memory before it is copied. If you need something more sophisticated for copying large files, feel free to add your improvements.
file
- The file to copy.dir
- The destination directory.
IOException
- For various reason: if file
does not exist or is not readable, if the
destination directory does not exist or isn't a directory, or if the file can't be
copied for any reason.public static String findRelativePath(File file, File relativeToDir) throws IOException
file
- file that the relative path should resolve torelativeToDir
- directory that the path should be relative to
IOException
public static String[] getPathComponents(String canonicalPath)
canonicalPath
- a file path that uses the OS file separator character
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |