Top Description Constructors Methods
org.apache.tomcat.util.http.fileupload

public Class FileUtils

extends Object
Class Inheritance
Imports
java.io.File, .FileNotFoundException, .IOException

General file manipulation utilities.

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 Summary

AccessConstructor and Description
public
FileUtils()

Instances should NOT be constructed in standard programming.

Method Summary

Modifier and TypeMethod and Description
public static void
cleanDirectory(final File
directory to clean
directory
)

Cleans a directory without deleting it.

private static void
cleanDirectoryOnExit(final File
directory to clean, must not be null
directory
)

Cleans a directory without deleting it.

public static void
deleteDirectory(final File
directory to delete
directory
)

Deletes a directory recursively.

private static void
deleteDirectoryOnExit(final File
directory to delete, must not be null
directory
)

Schedules a directory recursively for deletion on JVM exit.

public static void
forceDelete(final File
file or directory to delete, must not be null
file
)

Deletes a file.

public static void
forceDeleteOnExit(final File
file or directory to delete, must not be null
file
)

Schedules a file to be deleted when JVM exits.

public static void
forceMkdir(final File
directory to create, must not be null
directory
)

Makes a directory, including any necessary but nonexistent parent directories.

public static void
forceMkdirParent(final File
file with parent to create, must not be null
file
)

Makes any necessary but nonexistent parent directories for a given File.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

FileUtilsback to summary
public FileUtils()

Instances should NOT be constructed in standard programming.

Method Detail

cleanDirectoryback to summary
public static void cleanDirectory(final File directory) throws IOException

Cleans a directory without deleting it.

Parameters
directory:File

directory to clean

Exceptions
IOException:
in case cleaning is unsuccessful
IllegalArgumentException:
if directory does not exist or is not a directory
cleanDirectoryOnExitback to summary
private static void cleanDirectoryOnExit(final File directory) throws IOException

Cleans a directory without deleting it.

Parameters
directory:File

directory to clean, must not be null

Exceptions
IOException:
in case cleaning is unsuccessful
NullPointerException:
if the directory is null
deleteDirectoryback to summary
public static void deleteDirectory(final File directory) throws IOException

Deletes a directory recursively.

Parameters
directory:File

directory to delete

Exceptions
IOException:
in case deletion is unsuccessful
IllegalArgumentException:
if directory does not exist or is not a directory
deleteDirectoryOnExitback to summary
private static void deleteDirectoryOnExit(final File directory) throws IOException

Schedules a directory recursively for deletion on JVM exit.

Parameters
directory:File

directory to delete, must not be null

Exceptions
IOException:
in case deletion is unsuccessful
NullPointerException:
if the directory is null
forceDeleteback to summary
public static void forceDelete(final File file) throws IOException

Deletes 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

file or directory to delete, must not be null

Exceptions
IOException:
in case deletion is unsuccessful
NullPointerException:
if the directory is null
FileNotFoundException:
if the file was not found
forceDeleteOnExitback to summary
public static void forceDeleteOnExit(final File file) throws IOException

Schedules a file to be deleted when JVM exits. If file is directory delete it and all sub-directories.

Parameters
file:File

file or directory to delete, must not be null

Exceptions
IOException:
in case deletion is unsuccessful
NullPointerException:
if the file is null
forceMkdirback to summary
public static void forceMkdir(final File directory) throws IOException

Makes 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:File

directory to create, must not be null

Exceptions
IOException:
if the directory cannot be created or the file already exists but is not a directory
NullPointerException:
if the directory is null
forceMkdirParentback to summary
public static void forceMkdirParent(final File file) throws IOException

Makes 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

file with parent to create, must not be null

Exceptions
IOException:
if the parent directory cannot be created
NullPointerException:
if the file is null
Since
2.5