public final class FileUtils
extends java.lang.Object
| Constructor and Description |
|---|
FileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
createParentDir(java.io.File f)
Tries to create the ancestor directories of file f.
|
static void |
createParentDir(java.io.File f,
java.lang.String eMsg)
Tries to create the ancestor directories of file f.
|
static void |
createRestrictedDirectory(java.io.File directory)
Creates a new directory with minimum permissions.
|
static void |
createRestrictedFile(java.io.File file,
boolean writableByOwner)
Creates a new file with minimum permissions.
|
static void |
deleteWithErrMesg(java.io.File f)
Tries to delete file f.
|
static void |
deleteWithErrMesg(java.io.File f,
java.lang.String eMsg)
Tries to delete file f.
|
static java.lang.String |
displayablePath(java.lang.String path)
Returns a String that is suitable for using in GUI elements for
displaying (long) paths to users.
|
static java.lang.String |
displayablePath(java.lang.String path,
int visibleChars)
Return a String that is suitable for using in GUI elements for displaying
paths to users.
|
static java.nio.channels.FileLock |
getFileLock(java.lang.String path,
boolean shared,
boolean allowBlock)
This will return a lock to the file specified.
|
static void |
recursiveDelete(java.io.File file,
java.io.File base)
Recursively delete everything under a directory.
|
static java.lang.String |
sanitizeFileName(java.lang.String filename)
Given an input, return a sanitized form of the input suitable for use as
a file/directory name
|
static java.lang.String |
sanitizePath(java.lang.String path)
Clean up a string by removing characters that can't appear in a local
file name.
|
public static java.lang.String sanitizePath(java.lang.String path)
path - the path to sanitizepublic static java.lang.String sanitizeFileName(java.lang.String filename)
filename - the filename to sanitize.public static void createRestrictedDirectory(java.io.File directory)
throws java.io.IOException
java.io.IOExceptionpublic static void createRestrictedFile(java.io.File file,
boolean writableByOwner)
throws java.io.IOException
java.io.IOExceptionpublic static void createParentDir(java.io.File f,
java.lang.String eMsg)
throws java.io.IOException
f - eMsg - - the message to use for the exception. null
if the file name is to be used.java.io.IOException - if the directory can't be created and doesn't exist.public static void createParentDir(java.io.File f)
throws java.io.IOException
f - java.io.IOException - if the directory can't be created and doesn't exist.public static void deleteWithErrMesg(java.io.File f,
java.lang.String eMsg)
f - the file to be deletedeMsg - the message to print on failure (or null to print the
the file name).public static void deleteWithErrMesg(java.io.File f)
f - the file to be deletedpublic static java.lang.String displayablePath(java.lang.String path)
path - a path that should be shortenedpublic static java.lang.String displayablePath(java.lang.String path,
int visibleChars)
path - a path that should be shortedvisibleChars - the maximum number of characters that path should fit
into. Also the length of the returned stringpublic static void recursiveDelete(java.io.File file,
java.io.File base)
throws java.io.IOException
file - the file object representing what to delete. Can be either a
file or a directory.base - the directory under which the file and its subdirectories must be locatedjava.io.IOException - on an io exception or if trying to delete something
outside the basepublic static java.nio.channels.FileLock getFileLock(java.lang.String path,
boolean shared,
boolean allowBlock)
throws java.io.FileNotFoundException
path - File path to file we want to lock.shared - Specify if the lock will be a shared lock.allowBlock - Specify if we should block when we can not get the
lock. Getting a shared lock will always block.java.io.FileNotFoundException - If the file does not exist.