public class FileUtils extends Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
FileUtils.FilterWrapper |
Modifier and Type | Field and Description |
---|---|
static String |
FS
The vm file 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 and Description |
---|
FileUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
basename(String filename)
Returns the filename portion of a file specification string.
|
static String |
basename(String filename,
String suffix)
Returns the filename portion of a file specification string.
|
static String |
byteCountToDisplaySize(int size)
Returns a human-readable version of the file size (original is in bytes).
|
static String |
catPath(String lookupPath,
String path)
Will concatenate 2 paths.
|
static void |
cleanDirectory(File directory)
Clean a directory without deleting it.
|
static void |
cleanDirectory(String directory)
Clean a directory without deleting it.
|
static boolean |
contentEquals(File file1,
File file2)
Compare the contents of two files to determine if they are equal or not.
|
static void |
copyDirectory(File sourceDirectory,
File destinationDirectory)
Copy a directory to an other one.
|
static void |
copyDirectory(File sourceDirectory,
File destinationDirectory,
String includes,
String excludes)
Copy a directory to an other one.
|
static void |
copyDirectoryLayout(File sourceDirectory,
File destinationDirectory,
String[] includes,
String[] excludes)
Copies a entire directory layout : no files will be copied only directories
|
static void |
copyDirectoryStructure(File sourceDirectory,
File destinationDirectory)
Copies a entire directory structure.
|
static void |
copyDirectoryStructureIfModified(File sourceDirectory,
File destinationDirectory)
Copies an entire directory structure but only source files with timestamp later than the destinations'.
|
static void |
copyFile(File source,
File destination)
Copy file from source to destination.
|
static void |
copyFile(File from,
File to,
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(File from,
File to,
String encoding,
FileUtils.FilterWrapper[] wrappers,
boolean overwrite)
If wrappers is null or empty, the file will be copy only if
to.lastModified() < from.lastModified() , if overwrite is true |
static boolean |
copyFileIfModified(File source,
File destination)
Copy file from source to destination only if source timestamp is later than the destination timestamp.
|
static void |
copyFileToDirectory(File source,
File destinationDirectory)
Copy file from source to destination.
|
static void |
copyFileToDirectory(String source,
String destinationDirectory)
Copy file from source to destination.
|
static void |
copyFileToDirectoryIfModified(File source,
File destinationDirectory)
Copy file from source to destination only if source is newer than the target file.
|
static void |
copyFileToDirectoryIfModified(String source,
String destinationDirectory)
Copy file from source to destination only if source is newer than the target file.
|
static void |
copyStreamToFile(InputStreamFacade source,
File destination)
|
static void |
copyURLToFile(URL source,
File destination)
Copies bytes from the URL
source to a file destination . |
static File |
createTempFile(String prefix,
String suffix,
File parentDir)
Create a temporary file in a given directory.
|
static void |
deleteDirectory(File directory)
Recursively delete a directory.
|
static void |
deleteDirectory(String directory)
Recursively delete a directory.
|
static String |
dirname(String filename)
Returns the directory path portion of a file specification string.
|
static String |
extension(String filename)
Returns the extension portion of a file specification string.
|
static void |
fileAppend(String fileName,
String data)
Deprecated.
use
java.nio.files.Files.write(filename, data.getBytes(encoding),
StandardOpenOption.APPEND, StandardOpenOption.CREATE) |
static void |
fileAppend(String fileName,
String encoding,
String data)
Deprecated.
use
java.nio.files.Files.write(filename, data.getBytes(encoding),
StandardOpenOption.APPEND, StandardOpenOption.CREATE) |
static void |
fileDelete(String fileName)
Deletes a file.
|
static boolean |
fileExists(String fileName)
Check if a file exits.
|
static String |
filename(String filename)
Returns the filename portion of a file specification string.
|
static String |
fileRead(File file)
Note: the file content is read with platform encoding
|
static String |
fileRead(File file,
String encoding) |
static String |
fileRead(String file)
Note: the file content is read with platform encoding.
|
static String |
fileRead(String file,
String encoding) |
static void |
fileWrite(File file,
String data)
Writes data to a file.
|
static void |
fileWrite(File file,
String encoding,
String data)
Writes data to a file.
|
static void |
fileWrite(String fileName,
String data)
Writes data to a file.
|
static void |
fileWrite(String fileName,
String encoding,
String data)
Writes data to a file.
|
static void |
forceDelete(File file)
Delete a file.
|
static void |
forceDelete(String file)
Delete a file.
|
static void |
forceDeleteOnExit(File file)
Schedule a file to be deleted when JVM exits.
|
static void |
forceMkdir(File file)
Make a directory.
|
static String[] |
getDefaultExcludes() |
static List<String> |
getDefaultExcludesAsList() |
static String |
getDefaultExcludesAsString() |
static List<String> |
getDirectoryNames(File directory,
String includes,
String excludes,
boolean includeBasedir)
Return a list of directories as String depending options.
|
static List<String> |
getDirectoryNames(File directory,
String includes,
String excludes,
boolean includeBasedir,
boolean isCaseSensitive)
Return a list of directories as String depending options.
|
static String |
getExtension(String filename)
Get extension from filename.
|
static File |
getFile(String fileName)
Creates a file handle.
|
static List<String> |
getFileAndDirectoryNames(File directory,
String includes,
String excludes,
boolean includeBasedir,
boolean isCaseSensitive,
boolean getFiles,
boolean getDirectories)
Return a list of files as String depending options.
|
static List<String> |
getFileNames(File directory,
String includes,
String excludes,
boolean includeBasedir)
Return a list of files as String depending options.
|
static List<String> |
getFileNames(File directory,
String includes,
String excludes,
boolean includeBasedir,
boolean isCaseSensitive)
Return a list of files as String depending options.
|
static List<File> |
getFiles(File directory,
String includes,
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 List<File> |
getFiles(File directory,
String includes,
String excludes,
boolean includeBasedir)
Return the files contained in the directory, using inclusion and exclusion Ant patterns
|
static String[] |
getFilesFromExtension(String directory,
String[] extensions)
Given a directory and an array of extensions return an array of compliant files.
|
static String |
getPath(String filepath)
Get path from filename.
|
static String |
getPath(String filepath,
char fileSeparatorChar)
Get path from filename.
|
static boolean |
isValidWindowsFileName(File f)
For Windows OS, check if the file name contains any of the following characters:
":", "*", "?", "\"", "<", ">", "|" |
static void |
linkFile(File source,
File destination)
Link file from destination to source.
|
static List<String> |
loadFile(File file)
Note: the file content is read with platform encoding
|
static void |
mkdir(String dir)
Simple way to make a directory
|
static void |
mkDirs(File sourceBase,
String[] dirs,
File destination)
Creates a number of directories, as delivered from DirectoryScanner
|
static String |
normalize(String path)
Normalize a path.
|
static String |
removeExtension(String filename)
Remove extension from filename.
|
static String |
removePath(String filepath)
Remove path from filename.
|
static String |
removePath(String filepath,
char fileSeparatorChar)
Remove path from filename.
|
static void |
rename(File from,
File to)
Renames a file, even if that involves crossing file system boundaries.
|
static File |
resolveFile(File baseFile,
String filename)
Resolve a file
filename to it's canonical form. |
static long |
sizeOfDirectory(File directory)
Recursively count size of a directory.
|
static long |
sizeOfDirectory(String directory)
Recursively count size of a directory.
|
static File |
toFile(URL url)
Convert from a
URL to a File . |
static URL[] |
toURLs(File[] files)
Convert the array of Files into a list of URLs.
|
static boolean |
waitFor(File file,
int seconds)
Waits for NFS to propagate a file creation, imposing a timeout.
|
static boolean |
waitFor(String fileName,
int seconds)
Waits for NFS to propagate a file creation, imposing a timeout.
|
public static final int ONE_KB
public static final int ONE_MB
public static final int ONE_GB
public static String FS
public static String[] getDefaultExcludes()
AbstractScanner.DEFAULTEXCLUDES
public static List<String> getDefaultExcludesAsList()
getDefaultExcludes()
public static String getDefaultExcludesAsString()
AbstractScanner.DEFAULTEXCLUDES
,
StringUtils.join(Object[], String)
public static String byteCountToDisplaySize(int size)
size
- The number of bytes.public static String dirname(String filename)
filename
- the file pathpublic static String filename(String filename)
filename
- the file pathpublic static String basename(String filename)
filename
- the file pathpublic static String basename(String filename, String suffix)
filename
- the file pathsuffix
- the file suffixpublic static String extension(String filename)
filename
- the file pathpublic static boolean fileExists(String fileName)
fileName
- the file path.public static String fileRead(String file) throws IOException
file
- the file pathIOException
- if anypublic static String fileRead(String file, String encoding) throws IOException
file
- the file pathencoding
- the wanted encodingIOException
- if anypublic static String fileRead(File file) throws IOException
file
- the file pathIOException
- if anypublic static String fileRead(File file, String encoding) throws IOException
file
- the file pathencoding
- the wanted encodingIOException
- if anypublic static void fileAppend(String fileName, String data) throws IOException
java.nio.files.Files.write(filename, data.getBytes(encoding),
StandardOpenOption.APPEND, StandardOpenOption.CREATE)
fileName
- The path of the file to write.data
- The content to write to the file.IOException
- if anypublic static void fileAppend(String fileName, String encoding, String data) throws IOException
java.nio.files.Files.write(filename, data.getBytes(encoding),
StandardOpenOption.APPEND, StandardOpenOption.CREATE)
fileName
- The path of the file to write.encoding
- The encoding of the file.data
- The content to write to the file.IOException
- if anypublic static void fileWrite(String fileName, String data) throws IOException
fileName
- The path of the file to write.data
- The content to write to the file.IOException
- if anypublic static void fileWrite(String fileName, String encoding, String data) throws IOException
fileName
- The path of the file to write.encoding
- The encoding of the file.data
- The content to write to the file.IOException
- if anypublic static void fileWrite(File file, String data) throws IOException
file
- The file to write.data
- The content to write to the file.IOException
- if anypublic static void fileWrite(File file, String encoding, String data) throws IOException
file
- The file to write.encoding
- The encoding of the file.data
- The content to write to the file.IOException
- if anypublic static void fileDelete(String fileName)
fileName
- The path of the file to delete.public static boolean waitFor(String fileName, int seconds)
fileName
- The path of the file.seconds
- The maximum time in seconds to wait.public static boolean waitFor(File file, int seconds)
file
- The file.seconds
- The maximum time in seconds to wait.public static File getFile(String fileName)
fileName
- The path of the file.File
manager.public static String[] getFilesFromExtension(String directory, 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"
directory
- The path of the directory.extensions
- an array of expected extensions.public static void mkdir(String dir)
dir
- the directory to createIllegalArgumentException
- if the dir contains illegal Windows characters under Windows OS.INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
public static boolean contentEquals(File file1, File file2) throws IOException
file1
- the first filefile2
- the second fileIOException
- if anypublic static File toFile(URL url)
URL
to a File
.url
- File URL.File
object, or null
if the URL's protocol is not
file
public static URL[] toURLs(File[] files) throws IOException
files
- the array of filesIOException
- if an error occurspublic static String removeExtension(String filename)
foo.txt --> foo a\b\c.jpg --> a\b\c a\b\c --> a\b\c
filename
- the path of the filepublic static String getExtension(String filename)
foo.txt --> "txt" a\b\c.jpg --> "jpg" a\b\c --> ""
filename
- the path of the filepublic static String removePath(String filepath)
basename
ie.
a/b/c.txt --> c.txt a.txt --> a.txt
filepath
- the path of the filepublic static String removePath(String filepath, char fileSeparatorChar)
a/b/c.txt --> c.txt a.txt --> a.txt
filepath
- the path of the filefileSeparatorChar
- the file separator character like / on Unix platforms.public static String getPath(String filepath)
dirname
. ie.
a/b/c.txt --> a/b a.txt --> ""
filepath
- the filepathpublic static String getPath(String filepath, char fileSeparatorChar)
a/b/c.txt --> a/b a.txt --> ""
filepath
- the filepathfileSeparatorChar
- the file separator character like / on Unix platforms.public static void copyFileToDirectory(String source, String destinationDirectory) throws IOException
destinationDirectory
does not exist, it (and any parent
directories) will be created. If a file source
in destinationDirectory
exists, it will
be overwritten.source
- An existing File
to copy.destinationDirectory
- A directory to copy source
into.FileNotFoundException
- if source
isn't a normal file.IllegalArgumentException
- if destinationDirectory
isn't a directory.IOException
- if source
does not exist, the file in destinationDirectory
cannot
be written to, or an IO error occurs during copying.public static void copyFileToDirectoryIfModified(String source, String destinationDirectory) throws IOException
destinationDirectory
does not exist, it (and any parent directories) will be created. If a file
source
in destinationDirectory
exists, it will be overwritten.source
- An existing File
to copy.destinationDirectory
- A directory to copy source
into.FileNotFoundException
- if source
isn't a normal file.IllegalArgumentException
- if destinationDirectory
isn't a directory.IOException
- if source
does not exist, the file in destinationDirectory
cannot
be written to, or an IO error occurs during copying.public static void copyFileToDirectory(File source, File destinationDirectory) throws IOException
destinationDirectory
does not exist, it (and any parent
directories) will be created. If a file source
in destinationDirectory
exists, it will
be overwritten.source
- An existing File
to copy.destinationDirectory
- A directory to copy source
into.FileNotFoundException
- if source
isn't a normal file.IllegalArgumentException
- if destinationDirectory
isn't a directory.IOException
- if source
does not exist, the file in destinationDirectory
cannot
be written to, or an IO error occurs during copying.public static void copyFileToDirectoryIfModified(File source, File destinationDirectory) throws IOException
destinationDirectory
does not exist, it (and any parent directories) will be created. If a file
source
in destinationDirectory
exists, it will be overwritten.source
- An existing File
to copy.destinationDirectory
- A directory to copy source
into.FileNotFoundException
- if source
isn't a normal file.IllegalArgumentException
- if destinationDirectory
isn't a directory.IOException
- if source
does not exist, the file in destinationDirectory
cannot
be written to, or an IO error occurs during copying.public static void mkDirs(File sourceBase, String[] dirs, File destination) throws IOException
sourceBase
- The basedir used for the directory scandirs
- The getIncludedDirs from the dirscannerdestination
- The base dir of the output structureIOException
- io issuepublic static void copyFile(File source, File destination) throws IOException
destination
will be created if they
don't already exist. destination
will be overwritten if it already exists.source
- An existing non-directory File
to copy bytes from.destination
- A non-directory File
to write bytes to (possibly overwriting).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)
).public static void linkFile(File source, File destination) throws IOException
destination
will be created if they
don't already exist. destination
will be overwritten if it already exists.source
- An existing non-directory File
to link to.destination
- A non-directory File
becoming the link (possibly overwriting).IOException
- if source
does not exist, destination
cannot be created, or an
IO error occurs during linking.FileNotFoundException
- if destination
is a directory (use
copyFileToDirectory(java.lang.String, java.lang.String)
).public static boolean copyFileIfModified(File source, File destination) throws IOException
destination
will be created if they don't already exist. destination
will be overwritten if it already exists.source
- An existing non-directory File
to copy bytes from.destination
- A non-directory File
to write bytes to (possibly overwriting).IOException
- if source
does not exist, destination
cannot be written to, or an
IO error occurs during copying.public static void copyURLToFile(URL source, File destination) throws IOException
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.source
- A URL
to copy bytes from.destination
- A non-directory File
to write bytes to (possibly overwriting).IOException
- if
source
URL cannot be openeddestination
cannot be written topublic static void copyStreamToFile(InputStreamFacade source, File destination) throws IOException
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.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).IOException
- if
source
URL cannot be openeddestination
cannot be written topublic static String normalize(String path)
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
path
- the path to normalizenull
if too many ..'s.public static String catPath(String lookupPath, String path)
Will concatenate 2 paths. Paths with ..
will be properly handled.
/a/b/c + d = /a/b/d /a/b/c + ../d = /a/d
Thieved from Tomcat sources...
lookupPath
- a pathpath
- the path to concatenatepublic static File resolveFile(File baseFile, String filename)
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.baseFile
- Where to resolve filename
from, if filename
is relative.filename
- Absolute or relative file path to resolve.File
of filename
.public static void forceDelete(String file) throws IOException
file
- the file pathIOException
- if anypublic static void forceDelete(File file) throws IOException
file
- a fileIOException
- if anypublic static void forceDeleteOnExit(File file) throws IOException
file
- a fileIOException
- if anypublic static void forceMkdir(File file) throws IOException
file
- not nullIOException
- If there already exists a file with specified name or the directory is unable to be createdIllegalArgumentException
- if the file contains illegal Windows characters under Windows OS.INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
public static void deleteDirectory(String directory) throws IOException
directory
- a directoryIOException
- if anypublic static void deleteDirectory(File directory) throws IOException
directory
- a directoryIOException
- if anypublic static void cleanDirectory(String directory) throws IOException
directory
- a directoryIOException
- if anypublic static void cleanDirectory(File directory) throws IOException
directory
- a directoryIOException
- if anypublic static long sizeOfDirectory(String directory)
directory
- a directorypublic static long sizeOfDirectory(File directory)
directory
- a directorypublic static List<File> getFiles(File directory, String includes, String excludes) throws IOException
directory
- the directory to scanincludes
- the includes pattern, comma separatedexcludes
- the excludes pattern, comma separatedIOException
- io issuegetFileNames(File, String, String, boolean)
public static List<File> getFiles(File directory, String includes, String excludes, boolean includeBasedir) throws IOException
directory
- the directory to scanincludes
- the includes pattern, comma separatedexcludes
- the excludes pattern, comma separatedincludeBasedir
- true to include the base dir in each fileIOException
- io issuegetFileNames(File, String, String, boolean)
public static List<String> getFileNames(File directory, String includes, String excludes, boolean includeBasedir) throws IOException
directory
- the directory to scanincludes
- the includes pattern, comma separatedexcludes
- the excludes pattern, comma separatedincludeBasedir
- true to include the base dir in each String of fileIOException
- io issuepublic static List<String> getFileNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive) throws IOException
directory
- the directory to scanincludes
- the includes pattern, comma separatedexcludes
- the excludes pattern, comma separatedincludeBasedir
- true to include the base dir in each String of fileisCaseSensitive
- true if case sensitiveIOException
- io issuepublic static List<String> getDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir) throws IOException
directory
- the directory to scanincludes
- the includes pattern, comma separatedexcludes
- the excludes pattern, comma separatedincludeBasedir
- true to include the base dir in each String of fileIOException
- io issuepublic static List<String> getDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive) throws IOException
directory
- the directory to scanincludes
- the includes pattern, comma separatedexcludes
- the excludes pattern, comma separatedincludeBasedir
- true to include the base dir in each String of fileisCaseSensitive
- true if case sensitiveIOException
- io issuepublic static List<String> getFileAndDirectoryNames(File directory, String includes, String excludes, boolean includeBasedir, boolean isCaseSensitive, boolean getFiles, boolean getDirectories) throws IOException
directory
- the directory to scanincludes
- the includes pattern, comma separatedexcludes
- the excludes pattern, comma separatedincludeBasedir
- true to include the base dir in each String of fileisCaseSensitive
- true if case sensitivegetFiles
- true if get filesgetDirectories
- true if get directoriesIOException
- io issuepublic static void copyDirectory(File sourceDirectory, File destinationDirectory) throws IOException
sourceDirectory
- the source dirdestinationDirectory
- the target dirIOException
- if anypublic static void copyDirectory(File sourceDirectory, File destinationDirectory, String includes, String excludes) throws IOException
sourceDirectory
- the source dirdestinationDirectory
- the target dirincludes
- include patternexcludes
- exclude patternIOException
- if anygetFiles(File, String, String)
public 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:sourceDirectory
must exists.
sourceDirectory
- the source dirdestinationDirectory
- the target dirincludes
- include patternexcludes
- exclude patternIOException
- if anypublic static void copyDirectoryStructure(File sourceDirectory, File destinationDirectory) throws IOException
Copies a entire directory structure.
Note:sourceDirectory
must exists.
sourceDirectory
- the source dirdestinationDirectory
- the target dirIOException
- if anypublic 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:sourceDirectory
must exists.
sourceDirectory
- the source dirdestinationDirectory
- the target dirIOException
- if anypublic static void rename(File from, File to) throws 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.
from
- the file to moveto
- the new file nameIOException
- if anything bad happens during this process. Note that to
may have been deleted
already when this happens.public static File createTempFile(String prefix, String suffix, 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.
prefix
- prefix before the random numbersuffix
- file extension; include the '.'parentDir
- Directory to create the temporary file in -java.io.tmpdir
used if not specificedpublic static void copyFile(File from, File to, String encoding, FileUtils.FilterWrapper[] wrappers) throws IOException
to.lastModified() < from.lastModified()
from
- the file to copyto
- the destination fileencoding
- the file output encoding (only if wrappers is not empty)wrappers
- array of FileUtils.FilterWrapper
IOException
- if an IO error occurs during copying or filteringpublic static void copyFile(File from, File to, String encoding, FileUtils.FilterWrapper[] wrappers, boolean overwrite) throws IOException
to.lastModified() < from.lastModified()
, if overwrite is truefrom
- the file to copyto
- the destination fileencoding
- 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()
IOException
- if an IO error occurs during copying or filteringpublic static List<String> loadFile(File file) throws IOException
file
- the fileIOException
- if anypublic static boolean isValidWindowsFileName(File f)
":", "*", "?", "\"", "<", ">", "|"
f
- not null filefalse
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.INVALID_CHARACTERS_FOR_WINDOWS_FILE_NAME
Copyright © 2001–2022 The Apache Software Foundation. All rights reserved.