Computes the checksum of a file using the specified checksum object.
Computes the checksum of a file using the specified checksum object.
Multiple files may be checked using one Checksum
instance
if desired simply by reusing the same checksum object.
For example:
long csum = FileUtils.checksum(file, new CRC32()).getValue();
the checksum object to be used, must not be null
the checksum specified, updated with the content of the file
Computes the checksum of a file using the CRC32 checksum routine.
Computes the checksum of a file using the CRC32 checksum routine. The value of the checksum is returned.
Cleans a directory without deleting it.
Cleans a directory without deleting it.
this file
Compares the contents of two files to determine if they are equal or not.
Compares the contents of two files to determine if they are equal or not.
This method checks to see if the two files are different lengths or if they point to the same file, before resorting to byte-by-byte comparison of the contents.
Code origin: Avalon
the second file
true if the content of the files are equal or they both don't exist, false otherwise
Copies a filtered directory to a new location.
Copies a filtered directory to a new location.
This method copies the contents of the specified source directory to within the specified destination directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
Note: Setting preserveFileDate
to
true
tries to preserve the files' last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that those operations will succeed.
If the modification operation fails, no indication is provided.
the new directory, must not be null
the filter to apply, null means copy all directories and files
true if the file date of the copy should be the same as the original
the destination file
Copies a filtered directory to a new location.
Copies a filtered directory to a new location.
This method copies the contents of the specified source directory to within the specified destination directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
Note: Setting preserveFileDate
to
true
tries to preserve the files' last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that those operations will succeed.
If the modification operation fails, no indication is provided.
the new directory, must not be null
the filter to apply, null means copy all directories and files
the destination file
Copies a filtered directory to a new location.
Copies a filtered directory to a new location.
This method copies the contents of the specified source directory to within the specified destination directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
Note: Setting preserveFileDate
to
true
tries to preserve the files' last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that those operations will succeed.
If the modification operation fails, no indication is provided.
// only copy the directory structure copyDir(destDir, (file: File => file.isDirectory), false);
the new directory, must not be null
the filter to apply, null means copy all directories and files
true if the file date of the copy should be the same as the original
the destination file
Copies a filtered directory to a new location.
Copies a filtered directory to a new location.
This method copies the contents of the specified source directory to within the specified destination directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
Note: Setting preserveFileDate
to
true
tries to preserve the files' last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that those operations will succeed.
If the modification operation fails, no indication is provided.
// only copy the directory structure copyDir(destDir, (file: File => file.isDirectory), false);
the new directory, must not be null
the filter to apply, null means copy all directories and files
the destination file
Copies a whole directory to a new location.
Copies a whole directory to a new location.
This method copies the contents of the specified source directory to within the specified destination directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
Note: Setting preserveFileDate
to
true
tries to preserve the files' last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that those operations will succeed.
If the modification operation fails, no indication is provided.
the new directory, must not be null
should be the same as the original
the destination file
Copies a whole directory to a new location.
Copies a whole directory to a new location.
This method copies the contents of the specified source directory to within the specified destination directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
Note: Setting preserveFileDate
to
true
tries to preserve the files' last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that those operations will succeed.
If the modification operation fails, no indication is provided.
the new directory, must not be null
true if the file date of the copy should be the same as the original
the destination file
Copies a whole directory to a new location.
Copies a whole directory to a new location.
This method copies the contents of the specified source directory to within the specified destination directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
Note: Setting preserveFileDate
to
true
tries to preserve the files' last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that those operations will succeed.
If the modification operation fails, no indication is provided.
the new directory, must not be null
the destination file
Copies a whole directory to a new location.
Copies a whole directory to a new location.
This method copies the contents of the specified source directory to within the specified destination directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
Note: Setting preserveFileDate
to
true
tries to preserve the files' last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that those operations will succeed.
If the modification operation fails, no indication is provided.
the new directory, must not be null
the destination file
Copies a directory to within another directory preserving the file dates.
Copies a directory to within another directory preserving the file dates.
This method copies the source directory and all its contents to a directory of the same name in the specified destination directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
Note: This method tries to preserve the files' last
modified date/times using File#setLastModified(long)
, however
it is not guaranteed that those operations will succeed.
If the modification operation fails, no indication is provided.
the directory to place the copy in, must not be null
the destination file
Copies a directory to within another directory preserving the file dates.
Copies a directory to within another directory preserving the file dates.
This method copies the source directory and all its contents to a directory of the same name in the specified destination directory.
The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.
Note: This method tries to preserve the files' last
modified date/times using File#setLastModified(long)
, however
it is not guaranteed that those operations will succeed.
If the modification operation fails, no indication is provided.
the directory to place the copy in, must not be null
the destination file
Copies a file to a new location.
Copies a file to a new location.
This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.
the new file, must not be null
the destination file
Copies a file to a new location.
Copies a file to a new location.
This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.
Note: Setting preserveFileDate
to
true
tries to preserve the file's last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that the operation will succeed.
If the modification operation fails, no indication is provided.
the new file, must not be null
true if the file date of the copy should be the same as the original
the destination file
Copies a file to a new location.
Copies a file to a new location.
This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.
the new file, must not be null
the destination file
Copies a file to a new location.
Copies a file to a new location.
This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.
Note: Setting preserveFileDate
to
true
tries to preserve the file's last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that the operation will succeed.
If the modification operation fails, no indication is provided.
the new file, must not be null
true if the file date of the copy should be the same as the original
the destination file
Copies a file to a directory optionally preserving the file date.
Copies a file to a directory optionally preserving the file date.
This method copies the contents of the specified source file to a file of the same name in the specified destination directory. The destination directory is created if it does not exist. If the destination file exists, then this method will overwrite it.
Note: Setting preserveFileDate
to
true
tries to preserve the file's last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that the operation will succeed.
If the modification operation fails, no indication is provided.
the directory to place the copy in, must not be null
the destination file
Copies a file to a directory optionally preserving the file date.
Copies a file to a directory optionally preserving the file date.
This method copies the contents of the specified source file to a file of the same name in the specified destination directory. The destination directory is created if it does not exist. If the destination file exists, then this method will overwrite it.
Note: Setting preserveFileDate
to
true
tries to preserve the file's last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that the operation will succeed.
If the modification operation fails, no indication is provided.
the directory to place the copy in, must not be null
true if the file date of the copy should be the same as the original
the destination file
Copies a file to a directory optionally preserving the file date.
Copies a file to a directory optionally preserving the file date.
This method copies the contents of the specified source file to a file of the same name in the specified destination directory. The destination directory is created if it does not exist. If the destination file exists, then this method will overwrite it.
Note: Setting preserveFileDate
to
true
tries to preserve the file's last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that the operation will succeed.
If the modification operation fails, no indication is provided.
the directory to place the copy in, must not be null
the destination file
Copies a file to a directory optionally preserving the file date.
Copies a file to a directory optionally preserving the file date.
This method copies the contents of the specified source file to a file of the same name in the specified destination directory. The destination directory is created if it does not exist. If the destination file exists, then this method will overwrite it.
Note: Setting preserveFileDate
to
true
tries to preserve the file's last modified
date/times using File#setLastModified(long)
, however it is
not guaranteed that the operation will succeed.
If the modification operation fails, no indication is provided.
the directory to place the copy in, must not be null
true if the file date of the copy should be the same as the original
the destination file
Copies bytes from an InputStream
source
to a file
destination
.
Copies bytes from an 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.
the InputStream
to copy bytes from, must not be null
this file
Copies bytes from the URL source
to a file
destination
.
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.
the URL
to copy bytes from, must not be null
the number of milliseconds until this method will
timeout if no data could be read from the source
this file
Copies bytes from the URL source
to a file
destination
.
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.
the URL
to copy bytes from, must not be null
the number of milliseconds until this method will
timeout if no data could be read from the source
this file
Copies bytes from the URL source
to a file
destination
.
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.
Warning: this method does not set a connection or read timeout and thus
might block forever. Use #copyURLToFile(URL, File, int, int)
with reasonable timeouts to prevent this.
the URL
to copy bytes from, must not be null
this file
Copies bytes from the URL source
to a file
destination
.
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.
Warning: this method does not set a connection or read timeout and thus
might block forever. Use #copyURLToFile(URL, File, int, int)
with reasonable timeouts to prevent this.
the URL
to copy bytes from, must not be null
this file
Deletes a directory recursively.
Deletes a file, never throwing an exception.
Deletes a file, never throwing an exception. If file is a directory, delete it and all sub-directories.
The difference between File.delete() and this method are:
true
if the file or directory was deleted, otherwise
false
Returns a human-readable version of the file size, where the input represents a specific number of bytes.
Returns a human-readable version of the file size, where the input represents a specific number of bytes.
If the size is over 1GB, the size is returned as the number of whole GB, i.e. the size is rounded down to the nearest GB boundary.
Similarly for the 1MB and 1KB boundaries.
a human-readable display value (includes units - GB, MB, KB or bytes)
Deletes a file.
Deletes a file. If file is a directory, delete it and all sub-directories.
The difference between File.delete() and this method are:
Schedules a file to be deleted when JVM exits.
Schedules a file to be deleted when JVM exits. If file is directory delete it and all sub-directories.
Makes a directory, including any necessary but nonexistent parent directories.
Makes a directory, including any necessary but nonexistent parent directories. If a file already exists with specified name but it is not a directory then an IOException is thrown. If the directory cannot be created (or does not already exist) then an IOException is thrown.
this file
Tests if the specified File
is newer than the specified
time reference.
Tests if the specified File
is newer than the specified
time reference.
the time reference measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)
true if the File
exists and has been modified after
the given time reference.
Tests if the specified File
is newer than the specified
Date
.
Tests if the specified File
is newer than the specified
Date
.
the date reference, must not be null
true if the File
exists and has been modified
after the given Date
.
Tests if the specified File
is newer than the reference
File
.
Tests if the specified File
is newer than the reference
File
.
true if the File
exists and has been modified more
recently than the reference File
Tests if the specified File
is older than the specified
time reference.
Tests if the specified File
is older than the specified
time reference.
the time reference measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)
true if the File
exists and has been modified before
the given time reference.
Tests if the specified File
is older than the specified
Date
.
Tests if the specified File
is older than the specified
Date
.
the date reference, must not be null
true if the File
exists and has been modified
before the given Date
.
Tests if the specified File
is older than the reference
File
.
Tests if the specified File
is older than the reference
File
.
the File
of which the modification date
is used, must not be null
true if the File
exists and has been modified before
the reference File
Determines whether the specified file is a Symbolic Link rather than an actual file.
Determines whether the specified file is a Symbolic Link rather than an actual file.
Will not return true if there is a Symbolic Link anywhere in the path, only if the specific file is.
true if the file is a Symbolic Link
Returns an Iterator for the lines in a File
.
Returns an Iterator for the lines in a File
.
This method opens an InputStream
for the file.
When you have finished with the iterator you should close the stream
to free internal resources. This can be done by calling the
LineIterator#close()
or
LineIterator#closeQuietly(LineIterator)
method.
The recommended usage pattern is:
LineIterator it = file.lineIterator("UTF-8"); try { while (it.hasNext()) { String line = it.nextLine(); /// do something with line } } finally { LineIterator.closeQuietly(iterator); }
If an exception occurs during the creation of the iterator, the underlying stream is closed.
the encoding to use, null
means platform default
an Iterator of the lines in the file, never null
Finds files within a given directory which match an array of extensions.
Finds files within a given directory which match an array of extensions.
an array of extensions, ex. {"java","xml"}. If this
parameter is null
, all files are returned.
Finds files within a given directory and its subdirectories which match an array of extensions.
Finds files within a given directory and its subdirectories which match an array of extensions.
an array of extensions, ex. {"java","xml"}. If this
Finds files within a given directory and its subdirectories.
Moves a directory to another directory.
Moves a directory to another directory. create the destination directory
the destination file
the destination directory
Moves a directory to another directory.
Moves a directory to another directory. create the destination directory
the destination directory
Moves a directory.
Moves a directory.
When the destination directory is on another file system, do a "copy and delete".
the destination directory
Moves a directory.
Moves a directory.
When the destination directory is on another file system, do a "copy and delete".
the destination directory
the destination directory
Moves a directory to another directory.
Moves a directory to another directory.
If true
create the destination directory,
otherwise if false
throw an IOException
the destination directory
Moves a directory to another directory.
Moves a directory to another directory.
the destination file
If true
create the destination directory,
otherwise if false
throw an IOException
the destination directory
Moves a file.
Moves a file.
When the destination file is on another file system, do a "copy and delete".
the destination file
the destination file
Moves a file.
Moves a file.
When the destination file is on another file system, do a "copy and delete".
the destination file
the destination file
Moves a file to a directory.
Moves a file to a directory. create the destination directory.
the destination file
Moves a file to a directory.
Moves a file to a directory. create the destination directory.
the destination file
the destination file
Moves a file to a directory.
Moves a file to a directory.
If true
create the destination directory,
otherwise if false
throw an IOException
the destination file
Moves a file to a directory.
Moves a file to a directory.
the destination file
If true
create the destination directory,
otherwise if false
throw an IOException
the destination file
Moves a file or directory to the destination directory.
Moves a file or directory to the destination directory. create the destination directory,
When the destination is on another file system, do a "copy and delete".
the destination directory
the destination file or directory
Moves a file or directory to the destination directory.
Moves a file or directory to the destination directory. create the destination directory,
When the destination is on another file system, do a "copy and delete".
the destination directory
the destination file or directory
Moves a file or directory to the destination directory.
Moves a file or directory to the destination directory.
When the destination is on another file system, do a "copy and delete".
the destination directory
If true
create the destination directory,
otherwise if false
throw an IOException
the destination file or directory
Moves a file or directory to the destination directory.
Moves a file or directory to the destination directory.
When the destination is on another file system, do a "copy and delete".
the destination directory
If true
create the destination directory,
otherwise if false
throw an IOException
the destination file or directory
Opens a FileInputStream
for the specified file, providing better
error messages than simply calling new FileInputStream(file)
.
Opens a FileInputStream
for the specified file, providing better
error messages than simply calling new FileInputStream(file)
.
At the end of the method either the stream will be successfully opened, or an exception will have been thrown.
An exception is thrown if the file does not exist. An exception is thrown if the file object exists but is a directory. An exception is thrown if the file exists but cannot be read.
a new FileInputStream
for the specified file
Opens a FileOutputStream
for the specified file, checking and
creating the parent directory if it does not exist.
Opens a FileOutputStream
for the specified file, checking and
creating the parent directory if it does not exist.
At the end of the method either the stream will be successfully opened, or an exception will have been thrown.
The parent directory will be created if it does not exist. The file will be created if it does not exist. An exception is thrown if the file object exists but is a directory. An exception is thrown if the file exists but cannot be written to. An exception is thrown if the parent directory cannot be created.
a new FileOutputStream
for the specified file
Opens a FileInputStream
for the specified file, providing better
error messages than simply calling new FileInputStream(file)
.
Opens a FileInputStream
for the specified file, providing better
error messages than simply calling new FileInputStream(file)
.
At the end of the method either the stream will be successfully opened, or an exception will have been thrown.
An exception is thrown if the file does not exist. An exception is thrown if the file object exists but is a directory. An exception is thrown if the file exists but cannot be read.
a new FileInputStream
for the specified file
Opens a FileOutputStream
for the specified file, checking and
creating the parent directory if it does not exist.
Opens a FileOutputStream
for the specified file, checking and
creating the parent directory if it does not exist.
At the end of the method either the stream will be successfully opened, or an exception will have been thrown.
The parent directory will be created if it does not exist. The file will be created if it does not exist. An exception is thrown if the file object exists but is a directory. An exception is thrown if the file exists but cannot be written to. An exception is thrown if the parent directory cannot be created.
a new FileOutputStream
for the specified file
Reads the contents of a file line by line to a List of Strings.
Reads the contents of a file line by line to a List of Strings. The file is always closed.
the encoding to use, null
means platform default
the list of Strings representing each line in the file, never null
Reads the contents of a file into a byte array.
Reads the contents of a file into a byte array. The file is always closed.
the file contents, never null
Reads the contents of a file into a String.
Reads the contents of a file into a String. The file is always closed.
the encoding to use, null
means platform default
the file contents, never null
Returns the size of the specified file or directory.
Returns the size of the specified file or directory. If the provided
File
is a regular file, then the file's length is returned.
If the argument is a directory, then the size of the directory is
calculated recursively. If a directory or subdirectory is security
restricted, its size will not be included.
the length of the file, or recursive size of the directory, provided (in bytes).
Counts the size of a directory recursively (sum of the length of all files).
Counts the size of a directory recursively (sum of the length of all files).
size of directory in bytes, 0 if directory is security restricted
Implements the same behaviour as the "touch" utility on Unix.
Implements the same behaviour as the "touch" utility on Unix. It creates a new file with size 0 or, if the file exists already, it is opened and closed without modifying it, but updating the file date and time.
NOTE: As from v1.3, this method throws an IOException if the last modified date of the file cannot be set. Also, as from v1.3 this method creates parent directories if they do not exist.
Waits for NFS to propagate a file creation, imposing a timeout.
Waits for NFS to propagate a file creation, imposing a timeout.
This method repeatedly tests File#exists()
until it returns
true up to the maximum time specified in seconds.
true if file exists
Writes a byte array to a file creating the file if it does not exist.
Writes a byte array to a file creating the file if it does not exist.
NOTE: the parent directories of the file will be created if they do not exist.
the content to write to the file
this file
Writes a CharSequence to a file creating the file if it does not exist using the default encoding for the VM.
Writes a CharSequence to a file creating the file if it does not exist using the default encoding for the VM.
the content to write to the file
this file
Writes the toString()
value of each item in a collection to
the specified File
line by line.
Writes the toString()
value of each item in a collection to
the specified File
line by line.
The specified character encoding and the line ending will be used.
NOTE: the parent directories of the file will be created if they do not exist.
the lines to write, null
entries produce blank lines
the encoding to use, null
means platform default
the line separator to use, null
is system default
this file