public class FileUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
IGNORE_ERRORS
Option not to throw exceptions when a deletion finally doesn't succeed.
|
static int |
NONE
Option to delete given
File |
static int |
RECURSIVE
Option to recursively delete given
File |
static int |
RETRY
Option to retry deletion if not successful
|
static int |
SKIP_MISSING
Option to skip deletion if file doesn't exist
|
Constructor and Description |
---|
FileUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
createNewFile(java.io.File f)
Atomically creates a new, empty file named by this abstract pathname if
and only if a file with this name does not yet exist.
|
static void |
delete(java.io.File f)
Delete file or empty folder
|
static void |
delete(java.io.File f,
int options)
Delete file or folder
|
static void |
mkdir(java.io.File d)
Creates the directory named by this abstract pathname.
|
static void |
mkdir(java.io.File d,
boolean skipExisting)
Creates the directory named by this abstract pathname.
|
static void |
mkdirs(java.io.File d)
Creates the directory named by this abstract pathname, including any
necessary but nonexistent parent directories.
|
static void |
mkdirs(java.io.File d,
boolean skipExisting)
Creates the directory named by this abstract pathname, including any
necessary but nonexistent parent directories.
|
public static final int NONE
File
public static final int RECURSIVE
File
public static final int RETRY
public static final int SKIP_MISSING
public static final int IGNORE_ERRORS
public static void delete(java.io.File f) throws java.io.IOException
f
- File
to be deletedjava.io.IOException
- if deletion of f
fails. This may occur if f
didn't exist when the method was called. This can therefore
cause IOExceptions during race conditions when multiple
concurrent threads all try to delete the same file.public static void delete(java.io.File f, int options) throws java.io.IOException
f
- File
to be deletedoptions
- deletion options, RECURSIVE
for recursive deletion of
a subtree, RETRY
to retry when deletion failed.
Retrying may help if the underlying file system doesn't allow
deletion of files being read by another thread.java.io.IOException
- if deletion of f
fails. This may occur if f
didn't exist when the method was called. This can therefore
cause IOExceptions during race conditions when multiple
concurrent threads all try to delete the same file. This
exception is not thrown when IGNORE_ERRORS is set.public static void mkdir(java.io.File d) throws java.io.IOException
d
- directory to be createdjava.io.IOException
- if creation of d
fails. This may occur if d
did exist when the method was called. This can therefore
cause IOExceptions during race conditions when multiple
concurrent threads all try to create the same directory.public static void mkdir(java.io.File d, boolean skipExisting) throws java.io.IOException
d
- directory to be createdskipExisting
- if true
skip creation of the given directory if it
already exists in the file systemjava.io.IOException
- if creation of d
fails. This may occur if d
did exist when the method was called. This can therefore
cause IOExceptions during race conditions when multiple
concurrent threads all try to create the same directory.public static void mkdirs(java.io.File d) throws java.io.IOException
d
- directory to be createdjava.io.IOException
- if creation of d
fails. This may occur if d
did exist when the method was called. This can therefore
cause IOExceptions during race conditions when multiple
concurrent threads all try to create the same directory.public static void mkdirs(java.io.File d, boolean skipExisting) throws java.io.IOException
d
- directory to be createdskipExisting
- if true
skip creation of the given directory if it
already exists in the file systemjava.io.IOException
- if creation of d
fails. This may occur if d
did exist when the method was called. This can therefore
cause IOExceptions during race conditions when multiple
concurrent threads all try to create the same directory.public static void createNewFile(java.io.File f) throws java.io.IOException
Note: this method should not be used for file-locking, as the resulting
protocol cannot be made to work reliably. The FileLock
facility
should be used instead.
f
- the file to be createdjava.io.IOException
- if the named file already exists or if an I/O error occurredCopyright © 2012. All Rights Reserved.