org.codehaus.plexus.util

## Class FileUtils

- java.lang.Object
- - org.codehaus.plexus.util.FileUtils

    public class FileUtils
    extends java.lang.Object

This class provides basic facilities for manipulating files and file paths.

### Path-related methods

Methods exist to retrieve the components of a typical file path. For example `/www/hosted/mysite/index.html`, can be broken into:

- `/www/hosted/mysite/` -- retrievable through `getPath(java.lang.String)`
- `index.html` -- retrievable through `removePath(java.lang.String)`
- `/www/hosted/mysite/index` -- retrievable through `removeExtension(java.lang.String)`
- `html` -- retrievable through `getExtension(java.lang.String)`

There are also methods to `concatenate two paths`, `resolve a path relative to a File` and `normalize(java.lang.String)` a path.

### File-related methods

There are methods to create a `File from a URL`, copy a `File to a directory`, copy a `File to another File`, copy a `URL's contents to a File`, as well as methods to `delete` and `clean` a directory.

Common `File` manipulation routines.

Taken from the commons-utils repo. Also code from Alexandria's FileUtils. And from Avalon Excalibur's IO. And from Ant.

Version:
  $Id: FileUtils.java 8145 2009-03-25 19:54:54Z bentmann $
Author:
  Kevin A. Burton, Scott Sanders, Daniel Rall, Christoph.Reck, Peter Donald, Jeff Turner

### Nested Class Summary

Nested Classes
`static class` `FileUtils.FilterWrapper`

### Field Summary

Fields
`static java.lang.String` `FS` The vm line separator
`static int` `ONE_GB` The number of bytes in a gigabyte.
`static int` `ONE_KB` The number of bytes in a kilobyte.
`static int` `ONE_MB` The number of bytes in a megabyte.

### Constructor Summary

Constructors
Constructor and Description
`FileUtils()`

### Method Summary

Methods
`static java.lang.String` `basename(java.lang.String filename)` Returns the filename portion of a file specification string.
`static java.lang.String` `basename(java.lang.String filename, java.lang.String suffix)` Returns the filename portion of a file specification string.
`static java.lang.String` `byteCountToDisplaySize(int size)` Returns a human-readable version of the file size (original is in bytes).
`static java.lang.String` `catPath(java.lang.String lookupPath, java.lang.String path)` Will concatenate 2 paths.
`static void` `cleanDirectory(java.io.File directory)` Clean a directory without deleting it.
`static void` `cleanDirectory(java.lang.String directory)` Clean a directory without deleting it.
`static boolean` `contentEquals(java.io.File file1, java.io.File file2)` Compare the contents of two files to determine if they are equal or not.
`static void` `copyDirectory(java.io.File sourceDirectory, java.io.File destinationDirectory)` Copy a directory to an other one.
`static void` `copyDirectory(java.io.File sourceDirectory, java.io.File destinationDirectory, java.lang.String includes, java.lang.String excludes)` Copy a directory to an other one.
`static void` `copyDirectoryLayout(java.io.File sourceDirectory, java.io.File destinationDirectory, java.lang.String[] includes, java.lang.String[] excludes)` Copies a entire directory layout : no files will be copied only directories Note: It will include empty directories.
`static void` `copyDirectoryStructure(java.io.File sourceDirectory, java.io.File destinationDirectory)` Copies a entire directory structure.
`static void` `copyDirectoryStructureIfModified(java.io.File sourceDirectory, java.io.File destinationDirectory)` Copies an entire directory structure but only source files with timestamp later than the destinations'.
`static void` `copyFile(java.io.File source, java.io.File destination)` Copy file from source to destination.
`static void` `copyFile(java.io.File from, java.io.File to, java.lang.String encoding, FileUtils.FilterWrapper[] wrappers)` If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified()
`static void` `copyFile(java.io.File from, java.io.File to, java.lang.String encoding, FileUtils.FilterWrapper[] wrappers, boolean overwrite)` If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified() or if overwrite is true
`static boolean` `copyFileIfModified(java.io.File source, java.io.File destination)` Copy file from source to destination only if source timestamp is later than the destination timestamp.
`static void` `copyFileToDirectory(java.io.File source, java.io.File destinationDirectory)` Copy file from source to destination.
`static void` `copyFileToDirectory(java.lang.String source, java.lang.String destinationDirectory)` Copy file from source to destination.
`static void` `copyFileToDirectoryIfModified(java.io.File source, java.io.File destinationDirectory)` Copy file from source to destination only if source is newer than the target file.
`static void` `copyFileToDirectoryIfModified(java.lang.String source, java.lang.String destinationDirectory)` Copy file from source to destination only if source is newer than the target file.
`static void` `copyStreamToFile(InputStreamFacade source, java.io.File destination)` Copies bytes from the `InputStream` `source` to a file `destination`.
`static void` `copyURLToFile(java.net.URL source, java.io.File destination)` Copies bytes from the URL `source` to a file `destination`.
`static java.io.File` `createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File parentDir)` Create a temporary file in a given directory.
`static void` `deleteDirectory(java.io.File directory)` Recursively delete a directory.
`static void` `deleteDirectory(java.lang.String directory)` Recursively delete a directory.
`static java.lang.String` `dirname(java.lang.String filename)` Returns the directory path portion of a file specification string.
`static java.lang.String` `extension(java.lang.String filename)` Returns the extension portion of a file specification string.
`static void` `fileAppend(java.lang.String fileName, java.lang.String data)` Appends data to a file.
`static void` `fileAppend(java.lang.String fileName, java.lang.String encoding, java.lang.String data)` Appends data to a file.
`static void` `fileDelete(java.lang.String fileName)` Deletes a file.
`static boolean` `fileExists(java.lang.String fileName)` Check if a file exits.
`static java.lang.String` `filename(java.lang.String filename)` Returns the filename portion of a file specification string.
`static java.lang.String` `fileRead(java.io.File file)` Note: the file content is read with platform encoding
`static java.lang.String` `fileRead(java.io.File file, java.lang.String encoding)`
`static java.lang.String` `fileRead(java.lang.String file)` Note: the file content is read with platform encoding.
`static java.lang.String` `fileRead(java.lang.String file, java.lang.String encoding)`
`static void` `fileWrite(java.lang.String fileName, java.lang.String data)` Writes data to a file.
`static void` `fileWrite(java.lang.String fileName, java.lang.String encoding, java.lang.String data)` Writes data to a file.
`static void` `forceDelete(java.io.File file)` Delete a file.
`static void` `forceDelete(java.lang.String file)` Delete a file.
`static void` `forceDeleteOnExit(java.io.File file)` Schedule a file to be deleted when JVM exits.
`static void` `forceMkdir(java.io.File file)` Make a directory.
`static java.lang.String[]` `getDefaultExcludes()`
`static java.util.List` `getDefaultExcludesAsList()`
`static java.lang.String` `getDefaultExcludesAsString()`
`static java.util.List` `getDirectoryNames(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir)` Return a list of directories as String depending options.
`static java.util.List` `getDirectoryNames(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir, boolean isCaseSensitive)` Return a list of directories as String depending options.
`static java.lang.String` `getExtension(java.lang.String filename)` Get extension from filename.
`static java.io.File` `getFile(java.lang.String fileName)` Creates a file handle.
`static java.util.List` `getFileAndDirectoryNames(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir, boolean isCaseSensitive, boolean getFiles, boolean getDirectories)` Return a list of files as String depending options.
`static java.util.List` `getFileNames(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir)` Return a list of files as String depending options.
`static java.util.List` `getFileNames(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir, boolean isCaseSensitive)` Return a list of files as String depending options.
`static java.util.List` `getFiles(java.io.File directory, java.lang.String includes, java.lang.String excludes)` Return the files contained in the directory, using inclusion and exclusion Ant patterns, including the directory name in each of the files
`static java.util.List` `getFiles(java.io.File directory, java.lang.String includes, java.lang.String excludes, boolean includeBasedir)` Return the files contained in the directory, using inclusion and exclusion Ant patterns
`static java.lang.String[]` `getFilesFromExtension(java.lang.String directory, java.lang.String[] extensions)` Given a directory and an array of extensions return an array of compliant files.
`static java.lang.String` `getPath(java.lang.String filepath)` Get path from filename.
`static java.lang.String` `getPath(java.lang.String filepath, char fileSeparatorChar)` Get path from filename.
`static boolean` `isValidWindowsFileName(java.io.File f)` For Windows OS, check if the file name contains any of the following characters: `":", "*", "?", "\"", "<", ">", "|"`
`static java.util.List` `loadFile(java.io.File file)` Note: the file content is read with platform encoding
`static void` `mkdir(java.lang.String dir)` Simple way to make a directory
`static java.lang.String` `normalize(java.lang.String path)` Normalize a path.
`static java.lang.String` `removeExtension(java.lang.String filename)` Remove extension from filename.
`static java.lang.String` `removePath(java.lang.String filepath)` Remove path from filename.
`static java.lang.String` `removePath(java.lang.String filepath, char fileSeparatorChar)` Remove path from filename.
`static void` `rename(java.io.File from, java.io.File to)` Renames a file, even if that involves crossing file system boundaries.
`static java.io.File` `resolveFile(java.io.File baseFile, java.lang.String filename)` Resolve a file `filename` to it's canonical form.
`static long` `sizeOfDirectory(java.io.File directory)` Recursively count size of a directory.
`static long` `sizeOfDirectory(java.lang.String directory)` Recursively count size of a directory.
`static java.io.File` `toFile(java.net.URL url)` Convert from a `URL` to a `File`.
`static java.net.URL[]` `toURLs(java.io.File[] files)` Convert the array of Files into a list of URLs.
`static boolean` `waitFor(java.io.File file, int seconds)` Waits for NFS to propagate a file creation, imposing a timeout.
`static boolean` `waitFor(java.lang.String fileName, int seconds)` Waits for NFS to propagate a file creation, imposing a timeout.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### ONE_KB

    public static final int ONE_KB

The number of bytes in a kilobyte.

See Also:
  Constant Field Values

#### ONE_MB

    public static final int ONE_MB

The number of bytes in a megabyte.

See Also:
  Constant Field Values

#### ONE_GB

    public static final int ONE_GB

The number of bytes in a gigabyte.

See Also:
  Constant Field Values

#### FS

    public static java.lang.String FS

The vm line separator

### Constructor Detail

#### FileUtils

    public FileUtils()

### Method Detail

#### getDefaultExcludes

    public static java.lang.String[] getDefaultExcludes()

Returns:
  the default excludes pattern
See Also:
  `AbstractScanner.DEFAULTEXCLUDES`

#### getDefaultExcludesAsList

    public static java.util.List getDefaultExcludesAsList()

Returns:
  the default excludes pattern as list.
See Also:
  `getDefaultExcludes()`

#### getDefaultExcludesAsString

    public static java.lang.String getDefaultExcludesAsString()

Returns:
  the default excludes pattern as comma separated string.
See Also:
  `AbstractScanner.DEFAULTEXCLUDES`, `StringUtils.join(Object[], String)`

#### byteCountToDisplaySize

    public static java.lang.String byteCountToDisplaySize(int size)

Returns a human-readable version of the file size (original is in bytes).

Parameters:
  `size` - The number of bytes.
Returns:
  A human-readable display value (includes units).

#### dirname

    public static java.lang.String dirname(java.lang.String filename)

Returns the directory path portion of a file specification string. Matches the equally named unix command.

Parameters:
  `filename` - the file path
Returns:
  The directory portion excluding the ending file separator.

#### filename

    public static java.lang.String filename(java.lang.String filename)

Returns the filename portion of a file specification string.

Parameters:
  `filename` - the file path
Returns:
  The filename string with extension.

#### basename

    public static java.lang.String basename(java.lang.String filename)

Returns the filename portion of a file specification string. Matches the equally named unix command.

Parameters:
  `filename` - the file path
Returns:
  The filename string without extension.

#### basename

    public static java.lang.String basename(java.lang.String filename,
                            java.lang.String suffix)

Returns the filename portion of a file specification string. Matches the equally named unix command.

Parameters:
  `filename` - the file path
  `suffix` - the file suffix
Returns:
  the basename of the file

#### extension

    public static java.lang.String extension(java.lang.String filename)

Returns the extension portion of a file specification string. This everything after the last dot '.' in the filename (NOT including the dot).

Parameters:
  `filename` - the file path
Returns:
  the extension of the file

#### fileExists

    public static boolean fileExists(java.lang.String fileName)

Check if a file exits.

Parameters:
  `fileName` - the file path.
Returns:
  true if file exists.

#### fileRead

    public static java.lang.String fileRead(java.lang.String file)
                                     throws java.io.IOException

Note: the file content is read with platform encoding.

Parameters:
  `file` - the file path
Returns:
  the file content using the platform encoding.
Throws:
  `java.io.IOException` - if any

#### fileRead

    public static java.lang.String fileRead(java.lang.String file,
                            java.lang.String encoding)
                                     throws java.io.IOException

Parameters:
  `file` - the file path
  `encoding` - the wanted encoding
Returns:
  the file content using the specified encoding.
Throws:
  `java.io.IOException` - if any

#### fileRead

    public static java.lang.String fileRead(java.io.File file)
                                     throws java.io.IOException

Note: the file content is read with platform encoding

Parameters:
  `file` - the file path
Returns:
  the file content using the platform encoding.
Throws:
  `java.io.IOException` - if any

#### fileRead

    public static java.lang.String fileRead(java.io.File file,
                            java.lang.String encoding)
                                     throws java.io.IOException

Parameters:
  `file` - the file path
  `encoding` - the wanted encoding
Returns:
  the file content using the specified encoding.
Throws:
  `java.io.IOException` - if any

#### fileAppend

    public static void fileAppend(java.lang.String fileName,
                  java.lang.String data)
                           throws java.io.IOException

Appends data to a file. The file will be created if it does not exist. Note: the data is written with platform encoding

Parameters:
  `fileName` - The path of the file to write.
  `data` - The content to write to the file.
Throws:
  `java.io.IOException` - if any

#### fileAppend

    public static void fileAppend(java.lang.String fileName,
                  java.lang.String encoding,
                  java.lang.String data)
                           throws java.io.IOException

Appends data to a file. The file will be created if it does not exist.

Parameters:
  `fileName` - The path of the file to write.
  `encoding` - The encoding of the file.
  `data` - The content to write to the file.
Throws:
  `java.io.IOException` - if any

#### fileWrite

    public static void fileWrite(java.lang.String fileName,
                 java.lang.String data)
                          throws java.io.IOException

Writes data to a file. The file will be created if it does not exist. Note: the data is written with platform encoding

Parameters:
  `fileName` - The path of the file to write.
  `data` - The content to write to the file.
Throws:
  `java.io.IOException` - if any

#### fileWrite

    public static void fileWrite(java.lang.String fileName,
                 java.lang.String encoding,
                 java.lang.String data)
                          throws java.io.IOException

Writes data to a file. The file will be created if it does not exist.

Parameters:
  `fileName` - The path of the file to write.
  `encoding` - The encoding of the file.
  `data` - The content to write to the file.
Throws:
  `java.io.IOException` - if any

#### fileDelete

    public static void fileDelete(java.lang.String fileName)

Deletes a file.

Parameters:
  `fileName` - The path of the file to delete.

#### waitFor

    public static boolean waitFor(java.lang.String fileName,
                  int seconds)

Waits for NFS to propagate a file creation, imposing a timeout.

Parameters:
  `fileName` - The path of the file.
  `seconds` - The maximum time in seconds to wait.
Returns:
  True if file exists.

#### waitFor

    public static boolean waitFor(java.io.File file,
                  int seconds)

Waits for NFS to propagate a file creation, imposing a timeout.

Parameters:
  `file` - The file.
  `seconds` - The maximum time in seconds to wait.
Returns:
  True if file exists.

#### getFile

    public static java.io.File getFile(java.lang.String fileName)

Creates a file handle.

Parameters:
  `fileName` - The path of the file.
Returns:
  A `File` manager.

#### getFilesFromExtension

    public static java.lang.String[] getFilesFromExtension(java.lang.String directory,
                                           java.lang.String[] extensions)

Given a directory and an array of extensions return an array of compliant files.

TODO Should an ignore list be passed in? TODO Should a recurse flag be passed in?

The given extensions should be like "java" and not like ".java"

Parameters:
  `directory` - The path of the directory.
  `extensions` - an array of expected extensions.
Returns:
  An array of files for the wanted extensions.

#### mkdir

    public static void mkdir(java.lang.String dir)

Simple way to make a directory

Parameters:
  `dir` - the directory to create
Throws:
  `java.lang.IllegalArgumentException` - if the dir contains illegal Windows characters under Windows OS.
See Also:
  `INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME`

#### contentEquals

    public static boolean contentEquals(java.io.File file1,
                        java.io.File file2)
                                 throws java.io.IOException

Compare the contents of two files to determine if they are equal or not.

Parameters:
  `file1` - the first file
  `file2` - the second file
Returns:
  true if the content of the files are equal or they both don't exist, false otherwise
Throws:
  `java.io.IOException` - if any

#### toFile

    public static java.io.File toFile(java.net.URL url)

Convert from a `URL` to a `File`.

Parameters:
  `url` - File URL.
Returns:
  The equivalent `File` object, or `null` if the URL's protocol is not `file`

#### toURLs

    public static java.net.URL[] toURLs(java.io.File[] files)
                                 throws java.io.IOException

Convert the array of Files into a list of URLs.

Parameters:
  `files` - the array of files
Returns:
  the array of URLs
Throws:
  `java.io.IOException` - if an error occurs

#### removeExtension

    public static java.lang.String removeExtension(java.lang.String filename)

Remove extension from filename. ie

     foo.txt    --> foo
     a\b\c.jpg --> a\b\c
     a\b\c     --> a\b\c

Parameters:
  `filename` - the path of the file
Returns:
  the filename minus extension

#### getExtension

    public static java.lang.String getExtension(java.lang.String filename)

Get extension from filename. ie

     foo.txt    --> "txt"
     a\b\c.jpg --> "jpg"
     a\b\c     --> ""

Parameters:
  `filename` - the path of the file
Returns:
  the extension of filename or "" if none

#### removePath

    public static java.lang.String removePath(java.lang.String filepath)

Remove path from filename. Equivalent to the unix command `basename` ie.

     a/b/c.txt --> c.txt
     a.txt     --> a.txt

Parameters:
  `filepath` - the path of the file
Returns:
  the filename minus path

#### removePath

    public static java.lang.String removePath(java.lang.String filepath,
                              char fileSeparatorChar)

Remove path from filename. ie.

     a/b/c.txt --> c.txt
     a.txt     --> a.txt

Parameters:
  `filepath` - the path of the file
  `fileSeparatorChar` - the file separator character like / on Unix plateforms.
Returns:
  the filename minus path

#### getPath

    public static java.lang.String getPath(java.lang.String filepath)

Get path from filename. Roughly equivalent to the unix command `dirname`. ie.

     a/b/c.txt --> a/b
     a.txt     --> ""

Parameters:
  `filepath` - the filepath
Returns:
  the filename minus path

#### getPath

    public static java.lang.String getPath(java.lang.String filepath,
                           char fileSeparatorChar)

Get path from filename. ie.

     a/b/c.txt --> a/b
     a.txt     --> ""

Parameters:
  `filepath` - the filepath
  `fileSeparatorChar` - the file separator character like / on Unix plateforms.
Returns:
  the filename minus path

#### copyFileToDirectory

    public static void copyFileToDirectory(java.lang.String source,
                           java.lang.String destinationDirectory)
                                    throws java.io.IOException

Copy file from source to destination. If `destinationDirectory` does not exist, it (and any parent directories) will be created. If a file `source` in `destinationDirectory` exists, it will be overwritten.

Parameters:
  `source` - An existing `File` to copy.
  `destinationDirectory` - A directory to copy `source` into.
Throws:
  `java.io.FileNotFoundException` - if `source` isn't a normal file.
  `java.lang.IllegalArgumentException` - if `destinationDirectory` isn't a directory.
  `java.io.IOException` - if `source` does not exist, the file in `destinationDirectory` cannot be written to, or an IO error occurs during copying.

#### copyFileToDirectoryIfModified

    public static void copyFileToDirectoryIfModified(java.lang.String source,
                                     java.lang.String destinationDirectory)
                                              throws java.io.IOException

Copy file from source to destination only if source is newer than the target file. If `destinationDirectory` does not exist, it (and any parent directories) will be created. If a file `source` in `destinationDirectory` exists, it will be overwritten.

Parameters:
  `source` - An existing `File` to copy.
  `destinationDirectory` - A directory to copy `source` into.
Throws:
  `java.io.FileNotFoundException` - if `source` isn't a normal file.
  `java.lang.IllegalArgumentException` - if `destinationDirectory` isn't a directory.
  `java.io.IOException` - if `source` does not exist, the file in `destinationDirectory` cannot be written to, or an IO error occurs during copying.

#### copyFileToDirectory

    public static void copyFileToDirectory(java.io.File source,
                           java.io.File destinationDirectory)
                                    throws java.io.IOException

Copy file from source to destination. If `destinationDirectory` does not exist, it (and any parent directories) will be created. If a file `source` in `destinationDirectory` exists, it will be overwritten.

Parameters:
  `source` - An existing `File` to copy.
  `destinationDirectory` - A directory to copy `source` into.
Throws:
  `java.io.FileNotFoundException` - if `source` isn't a normal file.
  `java.lang.IllegalArgumentException` - if `destinationDirectory` isn't a directory.
  `java.io.IOException` - if `source` does not exist, the file in `destinationDirectory` cannot be written to, or an IO error occurs during copying.

#### copyFileToDirectoryIfModified

    public static void copyFileToDirectoryIfModified(java.io.File source,
                                     java.io.File destinationDirectory)
                                              throws java.io.IOException

Copy file from source to destination only if source is newer than the target file. If `destinationDirectory` does not exist, it (and any parent directories) will be created. If a file `source` in `destinationDirectory` exists, it will be overwritten.

Parameters:
  `source` - An existing `File` to copy.
  `destinationDirectory` - A directory to copy `source` into.
Throws:
  `java.io.FileNotFoundException` - if `source` isn't a normal file.
  `java.lang.IllegalArgumentException` - if `destinationDirectory` isn't a directory.
  `java.io.IOException` - if `source` does not exist, the file in `destinationDirectory` cannot be written to, or an IO error occurs during copying.

#### copyFile

    public static void copyFile(java.io.File source,
                java.io.File destination)
                         throws java.io.IOException

Copy file from source to destination. The directories up to `destination` will be created if they don't already exist. `destination` will be overwritten if it already exists.

Parameters:
  `source` - An existing non-directory `File` to copy bytes from.
  `destination` - A non-directory `File` to write bytes to (possibly overwriting).
Throws:
  `java.io.IOException` - if `source` does not exist, `destination` cannot be written to, or an IO error occurs during copying.
  `java.io.FileNotFoundException` - if `destination` is a directory (use `copyFileToDirectory(java.lang.String, java.lang.String)`).

#### copyFileIfModified

    public static boolean copyFileIfModified(java.io.File source,
                             java.io.File destination)
                                      throws java.io.IOException

Copy file from source to destination only if source timestamp is later than the destination timestamp. The directories up to `destination` will be created if they don't already exist. `destination` will be overwritten if it already exists.

Parameters:
  `source` - An existing non-directory `File` to copy bytes from.
  `destination` - A non-directory `File` to write bytes to (possibly overwriting).
Returns:
  true if no problem occured
Throws:
  `java.io.IOException` - if `source` does not exist, `destination` cannot be written to, or an IO error occurs during copying.
  `FileNotFoundException` - if `destination` is a directory (use `copyFileToDirectory(java.lang.String, java.lang.String)`).

#### copyURLToFile

    public static void copyURLToFile(java.net.URL source,
                     java.io.File destination)
                              throws java.io.IOException

Copies bytes from the URL `source` to a file `destination`. The directories up to `destination` will be created if they don't already exist. `destination` will be overwritten if it already exists.

Parameters:
  `source` - A `URL` to copy bytes from.
  `destination` - A non-directory `File` to write bytes to (possibly overwriting).
Throws:
  `java.io.IOException` - if
  - `source` URL cannot be opened
  - `destination` cannot be written to
  - an IO error occurs during copying

#### copyStreamToFile

    public static void copyStreamToFile(InputStreamFacade source,
                        java.io.File destination)
                                 throws java.io.IOException

Copies bytes from the `InputStream` `source` to a file `destination`. The directories up to `destination` will be created if they don't already exist. `destination` will be overwritten if it already exists.

Parameters:
  `source` - An `InputStream` to copy bytes from. This stream is guaranteed to be closed.
  `destination` - A non-directory `File` to write bytes to (possibly overwriting).
Throws:
  `java.io.IOException` - if
  - `source` URL cannot be opened
  - `destination` cannot be written to
  - an IO error occurs during copying

#### normalize

    public static java.lang.String normalize(java.lang.String path)

Normalize a path. Eliminates "/../" and "/./" in a string. Returns `null` if the ..'s went past the root. Eg:

     /foo//               -->     /foo/
     /foo/./              -->     /foo/
     /foo/../bar          -->     /bar
     /foo/../bar/         -->     /bar/
     /foo/../bar/../baz   -->     /baz
     //foo//./bar         -->     /foo/bar
     /../                 -->     null

Parameters:
  `path` - the path to normalize
Returns:
  the normalized String, or `null` if too many ..'s.

#### catPath

    public static java.lang.String catPath(java.lang.String lookupPath,
                           java.lang.String path)

Will concatenate 2 paths. Paths with `..` will be properly handled.

Eg.,
`/a/b/c` + `d` = `/a/b/d`
`/a/b/c` + `../d` = `/a/d`

Thieved from Tomcat sources...

Parameters:
  `lookupPath` - a path
  `path` - the path to concatenate
Returns:
  The concatenated paths, or null if error occurs

#### resolveFile

    public static java.io.File resolveFile(java.io.File baseFile,
                           java.lang.String filename)

Resolve a file `filename` to it's canonical form. If `filename` is relative (doesn't start with `/`), it will be resolved relative to `baseFile`, otherwise it is treated as a normal root-relative path.

Parameters:
  `baseFile` - Where to resolve `filename` from, if `filename` is relative.
  `filename` - Absolute or relative file path to resolve.
Returns:
  The canonical `File` of `filename`.

#### forceDelete

    public static void forceDelete(java.lang.String file)
                            throws java.io.IOException

Delete a file. If file is directory delete it and all sub-directories.

Parameters:
  `file` - the file path
Throws:
  `java.io.IOException` - if any

#### forceDelete

    public static void forceDelete(java.io.File file)
                            throws java.io.IOException

Delete a file. If file is directory delete it and all sub-directories.

Parameters:
  `file` - a file
Throws:
  `java.io.IOException` - if any

#### forceDeleteOnExit

    public static void forceDeleteOnExit(java.io.File file)
                                  throws java.io.IOException

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

Parameters:
  `file` - a file
Throws:
  `java.io.IOException` - if any

#### forceMkdir

    public static void forceMkdir(java.io.File file)
                           throws java.io.IOException

Make a directory.

Parameters:
  `file` - not null
Throws:
  `java.io.IOException` - If there already exists a file with specified name or the directory is unable to be created
  `java.lang.IllegalArgumentException` - if the file contains illegal Windows characters under Windows OS.
See Also:
  `INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME`

#### deleteDirectory

    public static void deleteDirectory(java.lang.String directory)
                                throws java.io.IOException

Recursively delete a directory.

Parameters:
  `directory` - a directory
Throws:
  `java.io.IOException` - if any

#### deleteDirectory

    public static void deleteDirectory(java.io.File directory)
                                throws java.io.IOException

Recursively delete a directory.

Parameters:
  `directory` - a directory
Throws:
  `java.io.IOException` - if any

#### cleanDirectory

    public static void cleanDirectory(java.lang.String directory)
                               throws java.io.IOException

Clean a directory without deleting it.

Parameters:
  `directory` - a directory
Throws:
  `java.io.IOException` - if any

#### cleanDirectory

    public static void cleanDirectory(java.io.File directory)
                               throws java.io.IOException

Clean a directory without deleting it.

Parameters:
  `directory` - a directory
Throws:
  `java.io.IOException` - if any

#### sizeOfDirectory

    public static long sizeOfDirectory(java.lang.String directory)

Recursively count size of a directory.

Parameters:
  `directory` - a directory
Returns:
  size of directory in bytes.

#### sizeOfDirectory

    public static long sizeOfDirectory(java.io.File directory)

Recursively count size of a directory.

Parameters:
  `directory` - a directory
Returns:
  size of directory in bytes.

#### getFiles

    public static java.util.List getFiles(java.io.File directory,
                          java.lang.String includes,
                          java.lang.String excludes)
                                   throws java.io.IOException

Return the files contained in the directory, using inclusion and exclusion Ant patterns, including the directory name in each of the files

Parameters:
  `directory` - the directory to scan
  `includes` - the includes pattern, comma separated
  `excludes` - the excludes pattern, comma separated
Returns:
  a list of File objects
Throws:
  `java.io.IOException`
See Also:
  `getFileNames( File, String, String, boolean )`

#### getFiles

    public static java.util.List getFiles(java.io.File directory,
                          java.lang.String includes,
                          java.lang.String excludes,
                          boolean includeBasedir)
                                   throws java.io.IOException

Return the files contained in the directory, using inclusion and exclusion Ant patterns

Parameters:
  `directory` - the directory to scan
  `includes` - the includes pattern, comma separated
  `excludes` - the excludes pattern, comma separated
  `includeBasedir` - true to include the base dir in each file
Returns:
  a list of File objects
Throws:
  `java.io.IOException`
See Also:
  `getFileNames( File, String, String, boolean )`

#### getFileNames

    public static java.util.List getFileNames(java.io.File directory,
                              java.lang.String includes,
                              java.lang.String excludes,
                              boolean includeBasedir)
                                       throws java.io.IOException

Return a list of files as String depending options. This method use case sensitive file name.

Parameters:
  `directory` - the directory to scan
  `includes` - the includes pattern, comma separated
  `excludes` - the excludes pattern, comma separated
  `includeBasedir` - true to include the base dir in each String of file
Returns:
  a list of files as String
Throws:
  `java.io.IOException`

#### getFileNames

    public static java.util.List getFileNames(java.io.File directory,
                              java.lang.String includes,
                              java.lang.String excludes,
                              boolean includeBasedir,
                              boolean isCaseSensitive)
                                       throws java.io.IOException

Return a list of files as String depending options.

Parameters:
  `directory` - the directory to scan
  `includes` - the includes pattern, comma separated
  `excludes` - the excludes pattern, comma separated
  `includeBasedir` - true to include the base dir in each String of file
  `isCaseSensitive` - true if case sensitive
Returns:
  a list of files as String
Throws:
  `java.io.IOException`

#### getDirectoryNames

    public static java.util.List getDirectoryNames(java.io.File directory,
                                   java.lang.String includes,
                                   java.lang.String excludes,
                                   boolean includeBasedir)
                                            throws java.io.IOException

Return a list of directories as String depending options. This method use case sensitive file name.

Parameters:
  `directory` - the directory to scan
  `includes` - the includes pattern, comma separated
  `excludes` - the excludes pattern, comma separated
  `includeBasedir` - true to include the base dir in each String of file
Returns:
  a list of directories as String
Throws:
  `java.io.IOException`

#### getDirectoryNames

    public static java.util.List getDirectoryNames(java.io.File directory,
                                   java.lang.String includes,
                                   java.lang.String excludes,
                                   boolean includeBasedir,
                                   boolean isCaseSensitive)
                                            throws java.io.IOException

Return a list of directories as String depending options.

Parameters:
  `directory` - the directory to scan
  `includes` - the includes pattern, comma separated
  `excludes` - the excludes pattern, comma separated
  `includeBasedir` - true to include the base dir in each String of file
  `isCaseSensitive` - true if case sensitive
Returns:
  a list of directories as String
Throws:
  `java.io.IOException`

#### getFileAndDirectoryNames

    public static java.util.List getFileAndDirectoryNames(java.io.File directory,
                                          java.lang.String includes,
                                          java.lang.String excludes,
                                          boolean includeBasedir,
                                          boolean isCaseSensitive,
                                          boolean getFiles,
                                          boolean getDirectories)
                                                   throws java.io.IOException

Return a list of files as String depending options.

Parameters:
  `directory` - the directory to scan
  `includes` - the includes pattern, comma separated
  `excludes` - the excludes pattern, comma separated
  `includeBasedir` - true to include the base dir in each String of file
  `isCaseSensitive` - true if case sensitive
  `getFiles` - true if get files
  `getDirectories` - true if get directories
Returns:
  a list of files as String
Throws:
  `java.io.IOException`

#### copyDirectory

    public static void copyDirectory(java.io.File sourceDirectory,
                     java.io.File destinationDirectory)
                              throws java.io.IOException

Copy a directory to an other one.

Parameters:
  `sourceDirectory` - the source dir
  `destinationDirectory` - the target dir
Throws:
  `java.io.IOException` - if any

#### copyDirectory

    public static void copyDirectory(java.io.File sourceDirectory,
                     java.io.File destinationDirectory,
                     java.lang.String includes,
                     java.lang.String excludes)
                              throws java.io.IOException

Copy a directory to an other one.

Parameters:
  `sourceDirectory` - the source dir
  `destinationDirectory` - the target dir
  `includes` - include pattern
  `excludes` - exlucde pattern
Throws:
  `java.io.IOException` - if any
See Also:
  `getFiles(File, String, String)`

#### copyDirectoryLayout

    public static void copyDirectoryLayout(java.io.File sourceDirectory,
                           java.io.File destinationDirectory,
                           java.lang.String[] includes,
                           java.lang.String[] excludes)
                                    throws java.io.IOException

Copies a entire directory layout : no files will be copied only directories

Note:

- It will include empty directories.
- The `sourceDirectory` must exists.

Parameters:
  `sourceDirectory` - the source dir
  `destinationDirectory` - the target dir
  `includes` - include pattern
  `excludes` - exlucde pattern
Throws:
  `java.io.IOException` - if any
Since:
  1.5.7

#### copyDirectoryStructure

    public static void copyDirectoryStructure(java.io.File sourceDirectory,
                              java.io.File destinationDirectory)
                                       throws java.io.IOException

Copies a entire directory structure.

Note:

- It will include empty directories.
- The `sourceDirectory` must exists.

Parameters:
  `sourceDirectory` - the source dir
  `destinationDirectory` - the target dir
Throws:
  `java.io.IOException` - if any

#### copyDirectoryStructureIfModified

    public static void copyDirectoryStructureIfModified(java.io.File sourceDirectory,
                                        java.io.File destinationDirectory)
                                                 throws java.io.IOException

Copies an entire directory structure but only source files with timestamp later than the destinations'.

Note:

- It will include empty directories.
- The `sourceDirectory` must exists.

Parameters:
  `sourceDirectory` - the source dir
  `destinationDirectory` - the target dir
Throws:
  `java.io.IOException` - if any

#### rename

    public static void rename(java.io.File from,
              java.io.File to)
                       throws java.io.IOException

Renames a file, even if that involves crossing file system boundaries.

This will remove `to` (if it exists), ensure that `to`'s parent directory exists and move `from`, which involves deleting `from` as well.

Parameters:
  `from` - the file to move
  `to` - the new file name
Throws:
  `java.io.IOException` - if anything bad happens during this process. Note that `to` may have been deleted already when this happens.

#### createTempFile

    public static java.io.File createTempFile(java.lang.String prefix,
                              java.lang.String suffix,
                              java.io.File parentDir)

Create a temporary file in a given directory.

The file denoted by the returned abstract pathname did not exist before this method was invoked, any subsequent invocation of this method will yield a different file name.

The filename is prefixNNNNNsuffix where NNNN is a random number

This method is different to `File.createTempFile(String, String, File)` of JDK 1.2 as it doesn't create the file itself. It uses the location pointed to by java.io.tmpdir when the parentDir attribute is null.

To delete automatically the file created by this method, use the `File.deleteOnExit()` method.

Parameters:
  `prefix` - prefix before the random number
  `suffix` - file extension; include the '.'
  `parentDir` - Directory to create the temporary file in `-java.io.tmpdir` used if not specificed
Returns:
  a File reference to the new temporary file.

#### copyFile

    public static void copyFile(java.io.File from,
                java.io.File to,
                java.lang.String encoding,
                FileUtils.FilterWrapper[] wrappers)
                         throws java.io.IOException

If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified()

Parameters:
  `from` - the file to copy
  `to` - the destination file
  `encoding` - the file output encoding (only if wrappers is not empty)
  `wrappers` - array of `FileUtils.FilterWrapper`
Throws:
  `java.io.IOException` - if an IO error occurs during copying or filtering

#### copyFile

    public static void copyFile(java.io.File from,
                java.io.File to,
                java.lang.String encoding,
                FileUtils.FilterWrapper[] wrappers,
                boolean overwrite)
                         throws java.io.IOException

If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified() or if overwrite is true

Parameters:
  `from` - the file to copy
  `to` - the destination file
  `encoding` - the file output encoding (only if wrappers is not empty)
  `wrappers` - array of `FileUtils.FilterWrapper`
  `overwrite` - if true and f wrappers is null or empty, the file will be copy enven if to.lastModified() < from.lastModified()
Throws:
  `java.io.IOException` - if an IO error occurs during copying or filtering
Since:
  1.5.2

#### loadFile

    public static java.util.List loadFile(java.io.File file)
                                   throws java.io.IOException

Note: the file content is read with platform encoding

Parameters:
  `file` - the file
Returns:
  a List containing every every line not starting with # and not empty
Throws:
  `java.io.IOException` - if any

#### isValidWindowsFileName

    public static boolean isValidWindowsFileName(java.io.File f)

For Windows OS, check if the file name contains any of the following characters: `":", "*", "?", "\"", "<", ">", "|"`

Parameters:
  `f` - not null file
Returns:
  `false` if the file path contains any of forbidden Windows characters, `true` if the Os is not Windows or if the file path respect the Windows constraints.
Since:
  1.5.2
See Also:
  `INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME`