Class FileUtils
- java.lang.Object
- 
- org.apache.tomcat.util.http.fileupload.FileUtils
 
- 
 public class FileUtils extends java.lang.ObjectGeneral file manipulation utilities.Facilities are provided in the following areas: - writing to a file
- reading from a file
- make a directory including parent directories
- copying files and directories
- deleting files and directories
- converting to and from a URL
- listing files and directories by filter and extension
- comparing file content
- file last changed date
- calculating a checksum
 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 SummaryConstructors Constructor Description FileUtils()Instances should NOT be constructed in standard programming.
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcleanDirectory(java.io.File directory)Cleans a directory without deleting it.static voiddeleteDirectory(java.io.File directory)Deletes a directory recursively.static voidforceDelete(java.io.File file)Deletes a file.static voidforceDeleteOnExit(java.io.File file)Schedules a file to be deleted when JVM exits.static voidforceMkdir(java.io.File directory)Makes a directory, including any necessary but nonexistent parent directories.static voidforceMkdirParent(java.io.File file)Makes any necessary but nonexistent parent directories for a given File.static booleanisSymlink(java.io.File file)Determines whether the specified file is a Symbolic Link rather than an actual file.
 
- 
- 
- 
Method Detail- 
deleteDirectorypublic static void deleteDirectory(java.io.File directory) throws java.io.IOExceptionDeletes a directory recursively.- Parameters:
- directory- directory to delete
- Throws:
- java.io.IOException- in case deletion is unsuccessful
- java.lang.IllegalArgumentException- if- directorydoes not exist or is not a directory
 
 - 
cleanDirectorypublic static void cleanDirectory(java.io.File directory) throws java.io.IOExceptionCleans a directory without deleting it.- Parameters:
- directory- directory to clean
- Throws:
- java.io.IOException- in case cleaning is unsuccessful
- java.lang.IllegalArgumentException- if- directorydoes not exist or is not a directory
 
 - 
forceDeletepublic static void forceDelete(java.io.File file) throws java.io.IOExceptionDeletes a file. If file is a directory, delete it and all sub-directories.The difference between File.delete() and this method are: - A directory to be deleted does not have to be empty.
- You get exceptions when a file or directory cannot be deleted. (java.io.File methods returns a boolean)
 - Parameters:
- file- file or directory to delete, must not be- null
- Throws:
- java.lang.NullPointerException- if the directory is- null
- java.io.FileNotFoundException- if the file was not found
- java.io.IOException- in case deletion is unsuccessful
 
 - 
forceDeleteOnExitpublic static void forceDeleteOnExit(java.io.File file) throws java.io.IOExceptionSchedules a file to be deleted when JVM exits. If file is directory delete it and all sub-directories.- Parameters:
- file- file or directory to delete, must not be- null
- Throws:
- java.lang.NullPointerException- if the file is- null
- java.io.IOException- in case deletion is unsuccessful
 
 - 
forceMkdirpublic static void forceMkdir(java.io.File directory) throws java.io.IOExceptionMakes a directory, including any necessary but nonexistent parent directories. If a file already exists with specified name but it is not a directory then an IOException is thrown. If the directory cannot be created (or does not already exist) then an IOException is thrown.- Parameters:
- directory- directory to create, must not be- null
- Throws:
- java.lang.NullPointerException- if the directory is- null
- java.io.IOException- if the directory cannot be created or the file already exists but is not a directory
 
 - 
forceMkdirParentpublic static void forceMkdirParent(java.io.File file) throws java.io.IOExceptionMakes any necessary but nonexistent parent directories for a given File. If the parent directory cannot be created then an IOException is thrown.- Parameters:
- file- file with parent to create, must not be- null
- Throws:
- java.lang.NullPointerException- if the file is- null
- java.io.IOException- if the parent directory cannot be created
- Since:
- 2.5
 
 - 
isSymlinkpublic static boolean isSymlink(java.io.File file) throws java.io.IOExceptionDetermines whether the specified file is a Symbolic Link rather than an actual file.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 falseif the system is detected as Windows usingFile.separatorChar== '\\'- Parameters:
- file- the file to check
- Returns:
- true if the file is a Symbolic Link
- Throws:
- java.io.IOException- if an IO error occurs while checking the file
- Since:
- 2.0
 
 
- 
 
-