Class FileUtils
This class provides basic facilities for manipulating files and file paths.
Path-related methodsMethods 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.
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.
- 
Nested Class SummaryNested Classes
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic StringReturns the filename portion of a file specification string.static StringReturns the filename portion of a file specification string.static StringbyteCountToDisplaySize(int size) Returns a human-readable version of the file size (original is in bytes).static StringWill concatenate 2 paths.static voidcleanDirectory(File directory) Clean a directory without deleting it.static voidcleanDirectory(String directory) Clean a directory without deleting it.static booleancontentEquals(File file1, File file2) Compare the contents of two files to determine if they are equal or not.static voidcopyDirectory(File sourceDirectory, File destinationDirectory) Copy a directory to an other one.static voidcopyDirectory(File sourceDirectory, File destinationDirectory, String includes, String excludes) Copy a directory to an other one.static voidcopyDirectoryLayout(File sourceDirectory, File destinationDirectory, String[] includes, String[] excludes) Copies a entire directory layout : no files will be copied only directoriesstatic voidcopyDirectoryStructure(File sourceDirectory, File destinationDirectory) Copies a entire directory structure.static voidcopyDirectoryStructureIfModified(File sourceDirectory, File destinationDirectory) Copies an entire directory structure but only source files with timestamp later than the destinations'.static voidCopy file from source to destination.static voidcopyFile(File from, File to, String encoding, FileUtils.FilterWrapper[] wrappers) If wrappers is null or empty, the file will be copy only ifto.lastModified() < from.lastModified()static voidcopyFile(File from, File to, String encoding, FileUtils.FilterWrapper[] wrappers, boolean overwrite) If wrappers is null or empty, the file will be copy only ifto.lastModified() < from.lastModified(), if overwrite is truestatic booleancopyFileIfModified(File source, File destination) Copy file from source to destination only if source timestamp is later than the destination timestamp.static voidcopyFileToDirectory(File source, File destinationDirectory) Copy file from source to destination.static voidcopyFileToDirectory(String source, String destinationDirectory) Copy file from source to destination.static voidcopyFileToDirectoryIfModified(File source, File destinationDirectory) Copy file from source to destination only if source is newer than the target file.static voidcopyFileToDirectoryIfModified(String source, String destinationDirectory) Copy file from source to destination only if source is newer than the target file.static voidcopyStreamToFile(InputStreamFacade source, File destination) static voidcopyURLToFile(URL source, File destination) Copies bytes from the URLsourceto a filedestination.static FilecreateTempFile(String prefix, String suffix, File parentDir) Create a temporary file in a given directory.static voiddeleteDirectory(File directory) Recursively delete a directory.static voiddeleteDirectory(String directory) Recursively delete a directory.static StringReturns the directory path portion of a file specification string.static StringReturns the extension portion of a file specification string.static voidfileAppend(String fileName, String data) Deprecated.static voidfileAppend(String fileName, String encoding, String data) Deprecated.usejava.nio.files.Files.write(filename, data.getBytes(encoding), StandardOpenOption.APPEND, StandardOpenOption.CREATE)static voidfileDelete(String fileName) Deletes a file.static booleanfileExists(String fileName) Check if a file exits.static StringReturns the filename portion of a file specification string.static StringNote: the file content is read with platform encodingstatic Stringstatic StringNote: the file content is read with platform encoding.static Stringstatic voidWrites data to a file.static voidWrites data to a file.static voidWrites data to a file.static voidWrites data to a file.static voidforceDelete(File file) Delete a file.static voidforceDelete(String file) Delete a file.static voidforceDeleteOnExit(File file) Schedule a file to be deleted when JVM exits.static voidforceMkdir(File file) Make a directory.static String[]static StringgetDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir) Return a list of directories as String depending options.getDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive) Return a list of directories as String depending options.static StringgetExtension(String filename) Get extension from filename.static FileCreates a file handle.getFileAndDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive, boolean getFiles, boolean getDirectories) Return a list of files as String depending options.getFileNames(File directory, String includes, String excludes, boolean includeBasedir) Return a list of files as String depending options.getFileNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive) Return a list of files as String depending options.Return the files contained in the directory, using inclusion and exclusion Ant patterns, including the directory name in each of the filesReturn the files contained in the directory, using inclusion and exclusion Ant patternsstatic String[]getFilesFromExtension(String directory, String[] extensions) Given a directory and an array of extensions return an array of compliant files.static StringGet path from filename.static StringGet path from filename.static booleanFor Windows OS, check if the file name contains any of the following characters:":", "*", "?", "\"", "<", ">", "|"static voidLink file from destination to source.Note: the file content is read with platform encodingstatic voidSimple way to make a directorystatic voidCreates a number of directories, as delivered from DirectoryScannerstatic StringNormalize a path.static StringremoveExtension(String filename) Remove extension from filename.static StringremovePath(String filepath) Remove path from filename.static StringremovePath(String filepath, char fileSeparatorChar) Remove path from filename.static voidRenames a file, even if that involves crossing file system boundaries.static FileresolveFile(File baseFile, String filename) Resolve a filefilenameto it's canonical form.static longsizeOfDirectory(File directory) Recursively count size of a directory.static longsizeOfDirectory(String directory) Recursively count size of a directory.static FileConvert from aURLto aFile.static URL[]Convert the array of Files into a list of URLs.static booleanWaits for NFS to propagate a file creation, imposing a timeout.static booleanWaits for NFS to propagate a file creation, imposing a timeout.
- 
Field Details- 
ONE_KBpublic static final int ONE_KBThe number of bytes in a kilobyte.- See Also:
 
- 
ONE_MBpublic static final int ONE_MBThe number of bytes in a megabyte.- See Also:
 
- 
ONE_GBpublic static final int ONE_GBThe number of bytes in a gigabyte.- See Also:
 
- 
FSThe vm file separator
 
- 
- 
Constructor Details- 
FileUtilspublic FileUtils()
 
- 
- 
Method Details- 
getDefaultExcludes- Returns:
- the default excludes pattern
- See Also:
 
- 
getDefaultExcludesAsList- Returns:
- the default excludes pattern as list.
- See Also:
 
- 
getDefaultExcludesAsString- Returns:
- the default excludes pattern as comma separated string.
- See Also:
 
- 
byteCountToDisplaySizeReturns 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).
 
- 
dirnameReturns 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.
 
- 
filenameReturns the filename portion of a file specification string.- Parameters:
- filename- the file path
- Returns:
- The filename string with extension.
 
- 
basenameReturns 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.
 
- 
basenameReturns 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
 
- 
extensionReturns 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
 
- 
fileExistsCheck if a file exits.- Parameters:
- fileName- the file path.
- Returns:
- true if file exists.
 
- 
fileReadNote: the file content is read with platform encoding.- Parameters:
- file- the file path
- Returns:
- the file content using the platform encoding.
- Throws:
- IOException- if any
 
- 
fileRead- Parameters:
- file- the file path
- encoding- the wanted encoding
- Returns:
- the file content using the specified encoding.
- Throws:
- IOException- if any
 
- 
fileReadNote: the file content is read with platform encoding- Parameters:
- file- the file path
- Returns:
- the file content using the platform encoding.
- Throws:
- IOException- if any
 
- 
fileRead- Parameters:
- file- the file path
- encoding- the wanted encoding
- Returns:
- the file content using the specified encoding.
- Throws:
- IOException- if any
 
- 
fileAppendDeprecated.usejava.nio.files.Files.write(filename, data.getBytes(encoding), StandardOpenOption.APPEND, StandardOpenOption.CREATE)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:
- IOException- if any
 
- 
fileAppendDeprecated.usejava.nio.files.Files.write(filename, data.getBytes(encoding), StandardOpenOption.APPEND, StandardOpenOption.CREATE)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:
- IOException- if any
 
- 
fileWriteWrites 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:
- IOException- if any
 
- 
fileWriteWrites 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:
- IOException- if any
 
- 
fileWriteWrites data to a file. The file will be created if it does not exist. Note: the data is written with platform encoding- Parameters:
- file- The file to write.
- data- The content to write to the file.
- Throws:
- IOException- if any
- Since:
- 2.0.6
 
- 
fileWriteWrites data to a file. The file will be created if it does not exist.- Parameters:
- file- The file to write.
- encoding- The encoding of the file.
- data- The content to write to the file.
- Throws:
- IOException- if any
- Since:
- 2.0.6
 
- 
fileDeleteDeletes a file.- Parameters:
- fileName- The path of the file to delete.
 
- 
waitForWaits 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.
 
- 
waitForWaits 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.
 
- 
getFileCreates a file handle.- Parameters:
- fileName- The path of the file.
- Returns:
- A Filemanager.
 
- 
getFilesFromExtensionGiven 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.
 
- 
mkdirSimple way to make a directory- Parameters:
- dir- the directory to create
- Throws:
- IllegalArgumentException- if the dir contains illegal Windows characters under Windows OS.
- See Also:
- 
- INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
 
 
- 
contentEqualsCompare 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:
- IOException- if any
 
- 
toFileConvert from aURLto aFile.- Parameters:
- url- File URL.
- Returns:
- The equivalent Fileobject, ornullif the URL's protocol is notfile
 
- 
toURLsConvert the array of Files into a list of URLs.- Parameters:
- files- the array of files
- Returns:
- the array of URLs
- Throws:
- IOException- if an error occurs
 
- 
removeExtensionRemove extension from filename. iefoo.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
 
- 
getExtensionGet extension from filename. iefoo.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
 
- 
removePathRemove path from filename. Equivalent to the unix commandbasenameie.a/b/c.txt --> c.txt a.txt --> a.txt - Parameters:
- filepath- the path of the file
- Returns:
- the filename minus path
 
- 
removePathRemove 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 platforms.
- Returns:
- the filename minus path
 
- 
getPathGet path from filename. Roughly equivalent to the unix commanddirname. ie.a/b/c.txt --> a/b a.txt --> "" - Parameters:
- filepath- the filepath
- Returns:
- the filename minus path
 
- 
getPathGet path from filename. ie.a/b/c.txt --> a/b a.txt --> "" - Parameters:
- filepath- the filepath
- fileSeparatorChar- the file separator character like / on Unix platforms.
- Returns:
- the filename minus path
 
- 
copyFileToDirectorypublic static void copyFileToDirectory(String source, String destinationDirectory) throws IOException Copy file from source to destination. IfdestinationDirectorydoes not exist, it (and any parent directories) will be created. If a filesourceindestinationDirectoryexists, it will be overwritten.- Parameters:
- source- An existing- Fileto copy.
- destinationDirectory- A directory to copy- sourceinto.
- Throws:
- FileNotFoundException- if- sourceisn't a normal file.
- IllegalArgumentException- if- destinationDirectoryisn't a directory.
- IOException- if- sourcedoes not exist, the file in- destinationDirectorycannot be written to, or an IO error occurs during copying.
 
- 
copyFileToDirectoryIfModifiedpublic static void copyFileToDirectoryIfModified(String source, String destinationDirectory) throws IOException Copy file from source to destination only if source is newer than the target file. IfdestinationDirectorydoes not exist, it (and any parent directories) will be created. If a filesourceindestinationDirectoryexists, it will be overwritten.- Parameters:
- source- An existing- Fileto copy.
- destinationDirectory- A directory to copy- sourceinto.
- Throws:
- FileNotFoundException- if- sourceisn't a normal file.
- IllegalArgumentException- if- destinationDirectoryisn't a directory.
- IOException- if- sourcedoes not exist, the file in- destinationDirectorycannot be written to, or an IO error occurs during copying.
 
- 
copyFileToDirectoryCopy file from source to destination. IfdestinationDirectorydoes not exist, it (and any parent directories) will be created. If a filesourceindestinationDirectoryexists, it will be overwritten.- Parameters:
- source- An existing- Fileto copy.
- destinationDirectory- A directory to copy- sourceinto.
- Throws:
- FileNotFoundException- if- sourceisn't a normal file.
- IllegalArgumentException- if- destinationDirectoryisn't a directory.
- IOException- if- sourcedoes not exist, the file in- destinationDirectorycannot be written to, or an IO error occurs during copying.
 
- 
copyFileToDirectoryIfModifiedpublic static void copyFileToDirectoryIfModified(File source, File destinationDirectory) throws IOException Copy file from source to destination only if source is newer than the target file. IfdestinationDirectorydoes not exist, it (and any parent directories) will be created. If a filesourceindestinationDirectoryexists, it will be overwritten.- Parameters:
- source- An existing- Fileto copy.
- destinationDirectory- A directory to copy- sourceinto.
- Throws:
- FileNotFoundException- if- sourceisn't a normal file.
- IllegalArgumentException- if- destinationDirectoryisn't a directory.
- IOException- if- sourcedoes not exist, the file in- destinationDirectorycannot be written to, or an IO error occurs during copying.
 
- 
mkDirsCreates a number of directories, as delivered from DirectoryScanner- Parameters:
- sourceBase- The basedir used for the directory scan
- dirs- The getIncludedDirs from the dirscanner
- destination- The base dir of the output structure
- Throws:
- IOException- io issue
 
- 
copyFileCopy file from source to destination. The directories up todestinationwill be created if they don't already exist.destinationwill be overwritten if it already exists.- Parameters:
- source- An existing non-directory- Fileto copy bytes from.
- destination- A non-directory- Fileto write bytes to (possibly overwriting).
- Throws:
- IOException- if- sourcedoes not exist,- destinationcannot be written to, or an IO error occurs during copying.
- FileNotFoundException- if- destinationis a directory (use- copyFileToDirectory(java.lang.String, java.lang.String)).
 
- 
linkFileLink file from destination to source. The directories up todestinationwill be created if they don't already exist.destinationwill be overwritten if it already exists.- Parameters:
- source- An existing non-directory- Fileto link to.
- destination- A non-directory- Filebecoming the link (possibly overwriting).
- Throws:
- IOException- if- sourcedoes not exist,- destinationcannot be created, or an IO error occurs during linking.
- FileNotFoundException- if- destinationis a directory (use- copyFileToDirectory(java.lang.String, java.lang.String)).
 
- 
copyFileIfModifiedCopy file from source to destination only if source timestamp is later than the destination timestamp. The directories up todestinationwill be created if they don't already exist.destinationwill be overwritten if it already exists.- Parameters:
- source- An existing non-directory- Fileto copy bytes from.
- destination- A non-directory- Fileto write bytes to (possibly overwriting).
- Returns:
- true if no problem occured
- Throws:
- IOException- if- sourcedoes not exist,- destinationcannot be written to, or an IO error occurs during copying.
 
- 
copyURLToFileCopies bytes from the URLsourceto a filedestination. The directories up todestinationwill be created if they don't already exist.destinationwill be overwritten if it already exists.- Parameters:
- source- A- URLto copy bytes from.
- destination- A non-directory- Fileto write bytes to (possibly overwriting).
- Throws:
- IOException- if- sourceURL cannot be opened
- destinationcannot be written to
- an IO error occurs during copying
 
 
- 
copyStreamToFileCopies bytes from theInputStreamsourceto a filedestination. The directories up todestinationwill be created if they don't already exist.destinationwill be overwritten if it already exists.- Parameters:
- source- An- InputStreamto copy bytes from. This stream is guaranteed to be closed.
- destination- A non-directory- Fileto write bytes to (possibly overwriting).
- Throws:
- IOException- if- sourceURL cannot be opened
- destinationcannot be written to
- an IO error occurs during copying
 
 
- 
normalizeNormalize a path. Eliminates "/../" and "/./" in a string. Returnsnullif 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 nullif too many ..'s.
 
- 
catPathWill concatenate 2 paths. Paths with Eg.,..will be properly handled./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
 
- 
resolveFileResolve a filefilenameto it's canonical form. Iffilenameis relative (doesn't start with/), it will be resolved relative tobaseFile, otherwise it is treated as a normal root-relative path.- Parameters:
- baseFile- Where to resolve- filenamefrom, if- filenameis relative.
- filename- Absolute or relative file path to resolve.
- Returns:
- The canonical Fileoffilename.
 
- 
forceDeleteDelete a file. If file is directory delete it and all sub-directories.- Parameters:
- file- the file path
- Throws:
- IOException- if any
 
- 
forceDeleteDelete a file. If file is directory delete it and all sub-directories.- Parameters:
- file- a file
- Throws:
- IOException- if any
 
- 
forceDeleteOnExitSchedule a file to be deleted when JVM exits. If file is directory delete it and all sub-directories.- Parameters:
- file- a file
- Throws:
- IOException- if any
 
- 
forceMkdirMake a directory.- Parameters:
- file- not null
- Throws:
- IOException- If there already exists a file with specified name or the directory is unable to be created
- IllegalArgumentException- if the file contains illegal Windows characters under Windows OS.
- See Also:
- 
- INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
 
 
- 
deleteDirectoryRecursively delete a directory.- Parameters:
- directory- a directory
- Throws:
- IOException- if any
 
- 
deleteDirectoryRecursively delete a directory.- Parameters:
- directory- a directory
- Throws:
- IOException- if any
 
- 
cleanDirectoryClean a directory without deleting it.- Parameters:
- directory- a directory
- Throws:
- IOException- if any
 
- 
cleanDirectoryClean a directory without deleting it.- Parameters:
- directory- a directory
- Throws:
- IOException- if any
 
- 
sizeOfDirectoryRecursively count size of a directory.- Parameters:
- directory- a directory
- Returns:
- size of directory in bytes.
 
- 
sizeOfDirectoryRecursively count size of a directory.- Parameters:
- directory- a directory
- Returns:
- size of directory in bytes.
 
- 
getFilespublic static List<File> getFiles(File directory, String includes, String excludes) throws 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:
- IOException- io issue
- See Also:
 
- 
getFilespublic static List<File> getFiles(File directory, String includes, String excludes, boolean includeBasedir) throws 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:
- IOException- io issue
- See Also:
 
- 
getFileNamespublic static List<String> getFileNames(File directory, String includes, String excludes, boolean includeBasedir) throws 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:
- IOException- io issue
 
- 
getFileNamespublic static List<String> getFileNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive) throws 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:
- IOException- io issue
 
- 
getDirectoryNamespublic static List<String> getDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir) throws 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:
- IOException- io issue
 
- 
getDirectoryNamespublic static List<String> getDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive) throws 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:
- IOException- io issue
 
- 
getFileAndDirectoryNamespublic static List<String> getFileAndDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive, boolean getFiles, boolean getDirectories) throws 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:
- IOException- io issue
 
- 
copyDirectorypublic static void copyDirectory(File sourceDirectory, File destinationDirectory) throws IOException Copy a directory to an other one.- Parameters:
- sourceDirectory- the source dir
- destinationDirectory- the target dir
- Throws:
- IOException- if any
 
- 
copyDirectorypublic static void copyDirectory(File sourceDirectory, File destinationDirectory, String includes, String excludes) throws IOException Copy a directory to an other one.- Parameters:
- sourceDirectory- the source dir
- destinationDirectory- the target dir
- includes- include pattern
- excludes- exclude pattern
- Throws:
- IOException- if any
- See Also:
 
- 
copyDirectoryLayoutpublic static void copyDirectoryLayout(File sourceDirectory, File destinationDirectory, String[] includes, String[] excludes) throws IOException Copies a entire directory layout : no files will be copied only directories Note:- It will include empty directories.
- The sourceDirectorymust exists.
 - Parameters:
- sourceDirectory- the source dir
- destinationDirectory- the target dir
- includes- include pattern
- excludes- exclude pattern
- Throws:
- IOException- if any
- Since:
- 1.5.7
 
- 
copyDirectoryStructurepublic static void copyDirectoryStructure(File sourceDirectory, File destinationDirectory) throws IOException Copies a entire directory structure. Note:- It will include empty directories.
- The sourceDirectorymust exists.
 - Parameters:
- sourceDirectory- the source dir
- destinationDirectory- the target dir
- Throws:
- IOException- if any
 
- 
copyDirectoryStructureIfModifiedpublic static void copyDirectoryStructureIfModified(File sourceDirectory, File destinationDirectory) throws IOException Copies an entire directory structure but only source files with timestamp later than the destinations'. Note:- It will include empty directories.
- The sourceDirectorymust exists.
 - Parameters:
- sourceDirectory- the source dir
- destinationDirectory- the target dir
- Throws:
- IOException- if any
 
- 
renameRenames a file, even if that involves crossing file system boundaries. This will remove to(if it exists), ensure thatto's parent directory exists and movefrom, which involves deletingfromas well.- Parameters:
- from- the file to move
- to- the new file name
- Throws:
- IOException- if anything bad happens during this process. Note that- tomay have been deleted already when this happens.
 
- 
createTempFileCreate 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.tmpdirused if not specificed
- Returns:
- a File reference to the new temporary file.
 
- 
copyFilepublic static void copyFile(File from, File to, String encoding, FileUtils.FilterWrapper[] wrappers) throws IOException If wrappers is null or empty, the file will be copy only ifto.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:
- IOException- if an IO error occurs during copying or filtering
 
- 
copyFilepublic static void copyFile(File from, File to, String encoding, FileUtils.FilterWrapper[] wrappers, boolean overwrite) throws IOException If wrappers is null or empty, the file will be copy only ifto.lastModified() < from.lastModified(), 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 wrappers is null or empty, the file will be copied even if- to.lastModified() < from.lastModified()
- Throws:
- IOException- if an IO error occurs during copying or filtering
- Since:
- 1.5.2
 
- 
loadFileNote: 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:
- IOException- if any
 
- 
isValidWindowsFileNameFor Windows OS, check if the file name contains any of the following characters:":", "*", "?", "\"", "<", ">", "|"- Parameters:
- f- not null file
- Returns:
- falseif the file path contains any of forbidden Windows characters,- trueif 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
 
 
 
- 
java.nio.files.Files.write(filename, data.getBytes(encoding), StandardOpenOption.APPEND, StandardOpenOption.CREATE)