public class SafeFileUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
CLEAN_LOCK |
static int |
DEFAULT_OPTIONS |
static int |
LOCK_FILE |
static long |
ONE_KB |
static long |
ONE_MB |
static int |
PRESERVE_DATE |
Constructor and Description |
---|
SafeFileUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
closeQuietly(java.nio.channels.FileChannel stream) |
static boolean |
closeQuietly(java.io.InputStream stream) |
static boolean |
closeQuietly(java.io.OutputStream stream) |
static void |
copyDirectory(java.io.File srcDir,
java.io.File destDir,
int options) |
static void |
copyFile(java.io.File srcFile,
java.io.File destFile)
Copies a file to a new location preserving the file date.
|
static void |
copyFile(java.io.File srcFile,
java.io.File destFile,
int options)
Copies a file to a new location.
|
static boolean |
deleteQuietly(java.io.File file)
Deletes a file, never throwing an exception.
|
static void |
moveDirectory(java.io.File srcDir,
java.io.File destDir) |
static void |
moveDirectory(java.io.File srcDir,
java.io.File destDir,
int options)
Moves a file.
|
static void |
moveFile(java.io.File srcFile,
java.io.File destFile) |
static void |
moveFile(java.io.File srcFile,
java.io.File destFile,
int options)
Moves a file.
|
static void |
setDefaultOptions(int options) |
public static final long ONE_KB
public static final long ONE_MB
public static final int LOCK_FILE
public static final int CLEAN_LOCK
public static final int PRESERVE_DATE
public static int DEFAULT_OPTIONS
public static void moveFile(java.io.File srcFile, java.io.File destFile, int options) throws java.io.IOException
When the destination file is on another file system, do a "copy and delete".
srcFile
- the file to be moveddestFile
- the destination filejava.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalidjava.io.IOException
- if an IO error occurs moving the filepublic static void moveFile(java.io.File srcFile, java.io.File destFile) throws java.io.IOException
java.io.IOException
public static void moveDirectory(java.io.File srcDir, java.io.File destDir, int options) throws java.io.IOException
When the destination file is on another file system, do a "copy and delete".
srcDir
- the file to be moveddestDir
- the destination filejava.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalidjava.io.IOException
- if an IO error occurs moving the filepublic static void copyDirectory(java.io.File srcDir, java.io.File destDir, int options) throws java.io.IOException
java.io.IOException
public static void moveDirectory(java.io.File srcDir, java.io.File destDir) throws java.io.IOException
java.io.IOException
public static boolean deleteQuietly(java.io.File file)
The difference between File.delete() and this method are:
file
- file or directory to delete, can be null
true
if the file or directory was deleted, otherwise
false
public static void copyFile(java.io.File srcFile, java.io.File destFile) throws java.io.IOException
This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.
Note: This method tries to preserve the file's last
modified date/times using File.setLastModified(long)
, however it
is not guaranteed that the operation will succeed. If the modification
operation fails, no indication is provided.
srcFile
- an existing file to copy, must not be null
destFile
- the new file, must not be null
java.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalidjava.io.IOException
- if an IO error occurs during copyingpublic static void copyFile(java.io.File srcFile, java.io.File destFile, int options) throws java.io.IOException
This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.
Note: Setting preserveFileDate
to
true
tries to preserve the file's last modified date/times using
File.setLastModified(long)
, however it is not guaranteed that the
operation will succeed. If the modification operation fails, no indication
is provided.
srcFile
- an existing file to copy, must not be null
destFile
- the new file, must not be null
options
- determine whether to use file locks and preserve date informationjava.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalidjava.io.IOException
- if an IO error occurs during copyingpublic static boolean closeQuietly(java.io.InputStream stream)
public static boolean closeQuietly(java.io.OutputStream stream)
public static boolean closeQuietly(java.nio.channels.FileChannel stream)
public static void setDefaultOptions(int options)