public class FileUtils
extends java.lang.Object
Facilities are provided in the following areas:
Note that a specific charset should be specified whenever possible. Relying on the platform default means that the code is Locale-dependent. Only use the default if the files are known to always use the platform default.
Origin of code: Excalibur, Alexandria, Commons-Utils
| Constructor and Description |
|---|
FileUtils()
Instances should NOT be constructed in standard programming.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
cleanDirectory(java.io.File directory)
Cleans a directory without deleting it.
|
static void |
deleteDirectory(java.io.File directory)
Deletes a directory recursively.
|
static void |
forceDelete(java.io.File file)
Deletes a file.
|
static void |
forceDeleteOnExit(java.io.File file)
Schedules a file to be deleted when JVM exits.
|
static void |
forceMkdir(java.io.File directory)
Makes a directory, including any necessary but nonexistent parent
directories.
|
static void |
forceMkdirParent(java.io.File file)
Makes any necessary but nonexistent parent directories for a given File.
|
static boolean |
isSymlink(java.io.File file)
Determines whether the specified file is a Symbolic Link rather than an actual file.
|
public FileUtils()
public static void deleteDirectory(java.io.File directory)
throws java.io.IOException
directory - directory to deletejava.io.IOException - in case deletion is unsuccessfuljava.lang.IllegalArgumentException - if directory does not exist or is not a directorypublic static void cleanDirectory(java.io.File directory)
throws java.io.IOException
directory - directory to cleanjava.io.IOException - in case cleaning is unsuccessfuljava.lang.IllegalArgumentException - if directory does not exist or is not a directorypublic static void forceDelete(java.io.File file)
throws java.io.IOException
The difference between File.delete() and this method are:
file - file or directory to delete, must not be nulljava.lang.NullPointerException - if the directory is nulljava.io.FileNotFoundException - if the file was not foundjava.io.IOException - in case deletion is unsuccessfulpublic static void forceDeleteOnExit(java.io.File file)
throws java.io.IOException
file - file or directory to delete, must not be nulljava.lang.NullPointerException - if the file is nulljava.io.IOException - in case deletion is unsuccessfulpublic static void forceMkdir(java.io.File directory)
throws java.io.IOException
directory - directory to create, must not be nulljava.lang.NullPointerException - if the directory is nulljava.io.IOException - if the directory cannot be created or the file already exists but is not a directorypublic static void forceMkdirParent(java.io.File file)
throws java.io.IOException
file - file with parent to create, must not be nulljava.lang.NullPointerException - if the file is nulljava.io.IOException - if the parent directory cannot be createdpublic static boolean isSymlink(java.io.File file)
throws java.io.IOException
Will not return true if there is a Symbolic Link anywhere in the path, only if the specific file is.
Note: the current implementation always returns false if
the system is detected as Windows using
File.separatorChar == '\\'
file - the file to checkjava.io.IOException - if an IO error occurs while checking the fileCopyright © 2000-2019 Apache Software Foundation. All Rights Reserved.