public class FileHelper extends Object
| Constructor and Description |
|---|
FileHelper() |
| Modifier and Type | Method and Description |
|---|---|
static void |
copyDir(File fileDirFrom, File fileDirTo)
Create a deep copy of the specified directory into the specified target directory.
|
static void |
copyFile(File fileFrom, File fileTo)
Copy the specified file according to the source and destination File objects preserving the time-stamp of the source.
|
static File |
createTempDir()
Create a unique temporary directory.
|
static void |
deleteDir(File fileDir)
Delete a directory recursively.
|
static void |
deleteDirSilent(File fileDir)
Recursively delete a directory suppressing any raised exceptions.
|
static File |
ensureDir(File file)
Validate that the given File represents a directory, creating it if it doesn't already exist.
|
static FileLock |
lockFile(File file)
Obtain an exclusive lock on the specified file.
|
static void |
moveDir(File fileDirFrom, File fileDirTo)
Move the specified directory to the specified destination path.
|
static void |
moveFile(File fileFrom, File fileTo)
Move the specified file to the specified destination path.
|
static long |
sizeDir(File fileDir)
Return the approximate disk usage in bytes for a given directory.
|
static String |
toFilename(String sName)
Given a string, return a derivative version that is safe to use for a filename.
|
static void |
unlockFile(FileLock lock)
Release an
exclusive lock on a file. |
static void |
validateDir(File file)
Validate that the given File exists and represents a directory.
|
public static String toFilename(String sName)
sName - the stringpublic static File ensureDir(File file) throws IOException
file - the File to checkIOException - on error creating the directorypublic static void validateDir(File file) throws IOException
file - the File to checkIOException - if the given File doesn't exist or doesn't represent a directorypublic static void copyDir(File fileDirFrom, File fileDirTo) throws IOException
fileDirFrom - the directory to copy fromfileDirTo - the directory to copy intoIOException - if an error occurred copying the directorypublic static void deleteDir(File fileDir) throws IOException
fileDir - directory to deleteIOException - if an error occurred deleting the directorypublic static void deleteDirSilent(File fileDir)
fileDir - directory to deletepublic static void moveDir(File fileDirFrom, File fileDirTo) throws IOException
fileDirFrom - the directory to movefileDirTo - the destination pathIOException - if an error occurred moving the directorypublic static File createTempDir() throws IOException
IOExceptionpublic static long sizeDir(File fileDir)
fileDir - the directory to sizepublic static void copyFile(File fileFrom, File fileTo) throws IOException
fileFrom - the File to copy fromfileTo - the File to copy toIOException - if an error occurred copying the filepublic static void moveFile(File fileFrom, File fileTo) throws IOException
fileFrom - the file to movefileTo - the destination pathIOException - if an error occurred moving the filepublic static FileLock lockFile(File file)
unlockFile method.file - the file to lockpublic static void unlockFile(FileLock lock)
exclusive lock on a file.lock - the exclusive lock to release