|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.io.FileUtils
public class FileUtils
General file manipulation utilities.
Facilities are provided in the following areas:
Origin of code: Excalibur, Alexandria, Commons-Utils
Field Summary | |
---|---|
static java.io.File[] |
EMPTY_FILE_ARRAY
An empty array of type File . |
static long |
ONE_GB
The number of bytes in a gigabyte. |
static long |
ONE_KB
The number of bytes in a kilobyte. |
static long |
ONE_MB
The number of bytes in a megabyte. |
Constructor Summary | |
---|---|
FileUtils()
Instances should NOT be constructed in standard programming. |
Method Summary | |
---|---|
static java.lang.String |
byteCountToDisplaySize(long size)
Returns a human-readable version of the file size, where the input represents a specific number of bytes. |
static java.util.zip.Checksum |
checksum(java.io.File file,
java.util.zip.Checksum checksum)
Computes the checksum of a file using the specified checksum object. |
static long |
checksumCRC32(java.io.File file)
Computes the checksum of a file using the CRC32 checksum routine. |
static void |
cleanDirectory(java.io.File 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 java.io.File[] |
convertFileCollectionToFileArray(java.util.Collection files)
Converts a Collection containing java.io.File instanced into array representation. |
static void |
copyDirectory(java.io.File srcDir,
java.io.File destDir)
Copies a whole directory to a new location preserving the file dates. |
static void |
copyDirectory(java.io.File srcDir,
java.io.File destDir,
boolean preserveFileDate)
Copies a whole directory to a new location. |
static void |
copyDirectoryToDirectory(java.io.File srcDir,
java.io.File destDir)
Copies a directory to within another directory preserving the file dates. |
static void |
copyFile(java.io.File srcFile,
java.io.File destFile)
Copies a file to a new location preserving the file date. |
static void |
copyFile(java.io.File srcFile,
java.io.File destFile,
boolean preserveFileDate)
Copies a file to a new location. |
static void |
copyFileToDirectory(java.io.File srcFile,
java.io.File destDir)
Copies a file to a directory preserving the file date. |
static void |
copyFileToDirectory(java.io.File srcFile,
java.io.File destDir,
boolean preserveFileDate)
Copies a file to a directory optionally preserving the file date. |
static void |
copyURLToFile(java.net.URL source,
java.io.File destination)
Copies bytes from the URL source to a file
destination . |
static void |
deleteDirectory(java.io.File directory)
Recursively delete a directory. |
static void |
forceDelete(java.io.File 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 directory)
Make a directory, including any necessary but nonexistent parent directories. |
static boolean |
isFileNewer(java.io.File file,
java.util.Date date)
Tests if the specified File is newer than the specified
Date . |
static boolean |
isFileNewer(java.io.File file,
java.io.File reference)
Tests if the specified File is newer than the reference
File . |
static boolean |
isFileNewer(java.io.File file,
long timeMillis)
Tests if the specified File is newer than the specified
time reference. |
static boolean |
isFileOlder(java.io.File file,
java.util.Date date)
Tests if the specified File is older than the specified
Date . |
static boolean |
isFileOlder(java.io.File file,
java.io.File reference)
Tests if the specified File is older than the reference
File . |
static boolean |
isFileOlder(java.io.File file,
long timeMillis)
Tests if the specified File is older than the specified
time reference. |
static java.util.Iterator |
iterateFiles(java.io.File directory,
IOFileFilter fileFilter,
IOFileFilter dirFilter)
Allows iteration over the files in given directory (and optionally its subdirectories). |
static java.util.Iterator |
iterateFiles(java.io.File directory,
java.lang.String[] extensions,
boolean recursive)
Allows iteration over the files in a given directory (and optionally its subdirectories) which match an array of extensions. |
static LineIterator |
lineIterator(java.io.File file)
Return an Iterator for the lines in a File using the default encoding for the VM. |
static LineIterator |
lineIterator(java.io.File file,
java.lang.String encoding)
Return an Iterator for the lines in a File . |
static java.util.Collection |
listFiles(java.io.File directory,
IOFileFilter fileFilter,
IOFileFilter dirFilter)
Finds files within a given directory (and optionally its subdirectories). |
static java.util.Collection |
listFiles(java.io.File directory,
java.lang.String[] extensions,
boolean recursive)
Finds files within a given directory (and optionally its subdirectories) which match an array of extensions. |
static java.io.FileInputStream |
openInputStream(java.io.File file)
Opens a FileInputStream for the specified file, providing better
error messages than simply calling new FileInputStream(file) . |
static java.io.FileOutputStream |
openOutputStream(java.io.File file)
Opens a FileOutputStream for the specified file, checking and
creating the parent directory if it does not exist. |
static byte[] |
readFileToByteArray(java.io.File file)
Reads the contents of a file into a byte array. |
static java.lang.String |
readFileToString(java.io.File file)
Reads the contents of a file into a String using the default encoding for the VM. |
static java.lang.String |
readFileToString(java.io.File file,
java.lang.String encoding)
Reads the contents of a file into a String. |
static java.util.List |
readLines(java.io.File file)
Reads the contents of a file line by line to a List of Strings using the default encoding for the VM. |
static java.util.List |
readLines(java.io.File file,
java.lang.String encoding)
Reads the contents of a file line by line to a List of Strings. |
static long |
sizeOfDirectory(java.io.File directory)
Recursively count size of a directory (sum of the length of all files). |
static java.io.File |
toFile(java.net.URL url)
Convert from a URL to a File . |
static java.io.File[] |
toFiles(java.net.URL[] urls)
Converts each of an array of URL to a File . |
static void |
touch(java.io.File file)
Implements the same behaviour as the "touch" utility on Unix. |
static java.net.URL[] |
toURLs(java.io.File[] files)
Converts each of an array of File to a URL . |
static boolean |
waitFor(java.io.File file,
int seconds)
Waits for NFS to propagate a file creation, imposing a timeout. |
static void |
writeByteArrayToFile(java.io.File file,
byte[] data)
Writes a byte array to a file creating the file if it does not exist. |
static void |
writeLines(java.io.File file,
java.util.Collection lines)
Writes the toString() value of each item in a collection to
the specified File line by line. |
static void |
writeLines(java.io.File file,
java.util.Collection lines,
java.lang.String lineEnding)
Writes the toString() value of each item in a collection to
the specified File line by line. |
static void |
writeLines(java.io.File file,
java.lang.String encoding,
java.util.Collection lines)
Writes the toString() value of each item in a collection to
the specified File line by line. |
static void |
writeLines(java.io.File file,
java.lang.String encoding,
java.util.Collection lines,
java.lang.String lineEnding)
Writes the toString() value of each item in a collection to
the specified File line by line. |
static void |
writeStringToFile(java.io.File file,
java.lang.String data)
Writes a String to a file creating the file if it does not exist using the default encoding for the VM. |
static void |
writeStringToFile(java.io.File file,
java.lang.String data,
java.lang.String encoding)
Writes a String to a file creating the file if it does not exist. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long ONE_KB
public static final long ONE_MB
public static final long ONE_GB
public static final java.io.File[] EMPTY_FILE_ARRAY
File
.
Constructor Detail |
---|
public FileUtils()
Method Detail |
---|
public static java.io.FileInputStream openInputStream(java.io.File file) throws java.io.IOException
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.
file
- the file to open for input, must not be null
FileInputStream
for the specified file
java.io.FileNotFoundException
- if the file does not exist
java.io.IOException
- if the file object is a directory
java.io.IOException
- if the file cannot be readpublic static java.io.FileOutputStream openOutputStream(java.io.File file) throws java.io.IOException
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.
file
- the file to open for output, must not be null
FileOutputStream
for the specified file
java.io.IOException
- if the file object is a directory
java.io.IOException
- if the file cannot be written to
java.io.IOException
- if a parent directory needs creating but that failspublic static java.lang.String byteCountToDisplaySize(long size)
size
- the number of bytes
public static void touch(java.io.File file) throws java.io.IOException
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.
file
- the File to touch
java.io.IOException
- If an I/O problem occurspublic static java.io.File[] convertFileCollectionToFileArray(java.util.Collection files)
files
- a Collection containing java.io.File instances
public static java.util.Collection listFiles(java.io.File directory, IOFileFilter fileFilter, IOFileFilter dirFilter)
If your search should recurse into subdirectories you can pass in an IOFileFilter for directories. You don't need to bind a DirectoryFileFilter (via logical AND) to this filter. This method does that for you.
An example: If you want to search through all directories called
"temp" you pass in FileFilterUtils.NameFileFilter("temp")
Another common usage of this method is find files in a directory
tree but ignoring the directories generated CVS. You can simply pass
in FileFilterUtils.makeCVSAware(null)
.
directory
- the directory to search infileFilter
- filter to apply when finding files.dirFilter
- optional filter to apply when finding subdirectories.
If this parameter is null
, subdirectories will not be included in the
search. Use TrueFileFilter.INSTANCE to match all directories.
FileFilterUtils
,
NameFileFilter
public static java.util.Iterator iterateFiles(java.io.File directory, IOFileFilter fileFilter, IOFileFilter dirFilter)
All files found are filtered by an IOFileFilter. This method is
based on listFiles(File, IOFileFilter, IOFileFilter)
.
directory
- the directory to search infileFilter
- filter to apply when finding files.dirFilter
- optional filter to apply when finding subdirectories.
If this parameter is null
, subdirectories will not be included in the
search. Use TrueFileFilter.INSTANCE to match all directories.
FileFilterUtils
,
NameFileFilter
public static java.util.Collection listFiles(java.io.File directory, java.lang.String[] extensions, boolean recursive)
directory
- the directory to search inextensions
- an array of extensions, ex. {"java","xml"}. If this
parameter is null
, all files are returned.recursive
- if true all subdirectories are searched as well
public static java.util.Iterator iterateFiles(java.io.File directory, java.lang.String[] extensions, boolean recursive)
listFiles(File, String[], boolean)
.
directory
- the directory to search inextensions
- an array of extensions, ex. {"java","xml"}. If this
parameter is null
, all files are returned.recursive
- if true all subdirectories are searched as well
public static boolean contentEquals(java.io.File file1, java.io.File file2) throws java.io.IOException
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
file1
- the first filefile2
- the second file
java.io.IOException
- in case of an I/O errorpublic static java.io.File toFile(java.net.URL url)
URL
to a File
.
From version 1.1 this method will decode the URL.
Syntax such as file:///my%20docs/file.txt
will be
correctly decoded to /my docs/file.txt
.
url
- the file URL to convert, null
returns null
File
object, or null
if the URL's protocol is not file
java.lang.IllegalArgumentException
- if the file is incorrectly encodedpublic static java.io.File[] toFiles(java.net.URL[] urls)
URL
to a File
.
Returns an array of the same size as the input.
If the input is null
, an empty array is returned.
If the input contains null
, the output array contains null
at the same
index.
This method will decode the URL.
Syntax such as file:///my%20docs/file.txt
will be
correctly decoded to /my docs/file.txt
.
urls
- the file URLs to convert, null
returns empty array
null
array of Files matching the input, with a null
item
if there was a null
at that index in the input array
java.lang.IllegalArgumentException
- if any file is not a URL file
java.lang.IllegalArgumentException
- if any file is incorrectly encodedpublic static java.net.URL[] toURLs(java.io.File[] files) throws java.io.IOException
File
to a URL
.
Returns an array of the same size as the input.
files
- the files to convert
java.io.IOException
- if a file cannot be convertedpublic static void copyFileToDirectory(java.io.File srcFile, java.io.File destDir) throws java.io.IOException
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.
srcFile
- an existing file to copy, must not be null
destDir
- the directory to place the copy in, must not be null
java.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalid
java.io.IOException
- if an IO error occurs during copyingcopyFile(File, File, boolean)
public static void copyFileToDirectory(java.io.File srcFile, java.io.File destDir, boolean preserveFileDate) throws java.io.IOException
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.
srcFile
- an existing file to copy, must not be null
destDir
- the directory to place the copy in, must not be null
preserveFileDate
- true if the file date of the copy
should be the same as the original
java.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalid
java.io.IOException
- if an IO error occurs during copyingcopyFile(File, File, boolean)
public static void copyFile(java.io.File srcFile, java.io.File destFile) throws java.io.IOException
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.
srcFile
- an existing file to copy, must not be null
destFile
- the new file, must not be null
java.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalid
java.io.IOException
- if an IO error occurs during copyingcopyFileToDirectory(File, File)
public static void copyFile(java.io.File srcFile, java.io.File destFile, boolean preserveFileDate) throws java.io.IOException
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.
srcFile
- an existing file to copy, must not be null
destFile
- the new file, must not be null
preserveFileDate
- true if the file date of the copy
should be the same as the original
java.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalid
java.io.IOException
- if an IO error occurs during copyingcopyFileToDirectory(File, File, boolean)
public static void copyDirectoryToDirectory(java.io.File srcDir, java.io.File destDir) throws java.io.IOException
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.
srcDir
- an existing directory to copy, must not be null
destDir
- the directory to place the copy in, must not be null
java.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalid
java.io.IOException
- if an IO error occurs during copyingpublic static void copyDirectory(java.io.File srcDir, java.io.File destDir) throws java.io.IOException
This method copies the specified directory and all its child directories and files to the specified destination. The destination is the new location and name of the 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.
srcDir
- an existing directory to copy, must not be null
destDir
- the new directory, must not be null
java.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalid
java.io.IOException
- if an IO error occurs during copyingpublic static void copyDirectory(java.io.File srcDir, java.io.File destDir, boolean preserveFileDate) throws java.io.IOException
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.
srcDir
- an existing directory to copy, must not be null
destDir
- the new directory, must not be null
preserveFileDate
- true if the file date of the copy
should be the same as the original
java.lang.NullPointerException
- if source or destination is null
java.io.IOException
- if source or destination is invalid
java.io.IOException
- if an IO error occurs during copyingpublic static void copyURLToFile(java.net.URL source, java.io.File destination) throws java.io.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
- the URL
to copy bytes from, must not be null
destination
- the non-directory File
to write bytes to
(possibly overwriting), must not be null
java.io.IOException
- if source
URL cannot be opened
java.io.IOException
- if destination
is a directory
java.io.IOException
- if destination
cannot be written
java.io.IOException
- if destination
needs creating but can't be
java.io.IOException
- if an IO error occurs during copyingpublic static void deleteDirectory(java.io.File directory) throws java.io.IOException
directory
- directory to delete
java.io.IOException
- in case deletion is unsuccessfulpublic static void cleanDirectory(java.io.File directory) throws java.io.IOException
directory
- directory to clean
java.io.IOException
- in case cleaning is unsuccessfulpublic static boolean waitFor(java.io.File file, int seconds)
This method repeatedly tests File.exists()
until it returns
true up to the maximum time specified in seconds.
file
- the file to check, must not be null
seconds
- the maximum time in seconds to wait
java.lang.NullPointerException
- if the file is null
public static java.lang.String readFileToString(java.io.File file, java.lang.String encoding) throws java.io.IOException
file
- the file to read, must not be null
encoding
- the encoding to use, null
means platform default
null
java.io.IOException
- in case of an I/O error
java.io.UnsupportedEncodingException
- if the encoding is not supported by the VMpublic static java.lang.String readFileToString(java.io.File file) throws java.io.IOException
file
- the file to read, must not be null
null
java.io.IOException
- in case of an I/O errorpublic static byte[] readFileToByteArray(java.io.File file) throws java.io.IOException
file
- the file to read, must not be null
null
java.io.IOException
- in case of an I/O errorpublic static java.util.List readLines(java.io.File file, java.lang.String encoding) throws java.io.IOException
file
- the file to read, must not be null
encoding
- the encoding to use, null
means platform default
null
java.io.IOException
- in case of an I/O error
java.io.UnsupportedEncodingException
- if the encoding is not supported by the VMpublic static java.util.List readLines(java.io.File file) throws java.io.IOException
file
- the file to read, must not be null
null
java.io.IOException
- in case of an I/O errorpublic static LineIterator lineIterator(java.io.File file, java.lang.String encoding) throws java.io.IOException
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 = FileUtils.lineIterator(file, "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.
file
- the file to open for input, must not be null
encoding
- the encoding to use, null
means platform default
null
java.io.IOException
- in case of an I/O error (file closed)public static LineIterator lineIterator(java.io.File file) throws java.io.IOException
File
using the default encoding for the VM.
file
- the file to open for input, must not be null
null
java.io.IOException
- in case of an I/O error (file closed)lineIterator(File, String)
public static void writeStringToFile(java.io.File file, java.lang.String data, java.lang.String encoding) throws java.io.IOException
file
- the file to writedata
- the content to write to the fileencoding
- the encoding to use, null
means platform default
java.io.IOException
- in case of an I/O error
java.io.UnsupportedEncodingException
- if the encoding is not supported by the VMpublic static void writeStringToFile(java.io.File file, java.lang.String data) throws java.io.IOException
file
- the file to writedata
- the content to write to the file
java.io.IOException
- in case of an I/O errorpublic static void writeByteArrayToFile(java.io.File file, byte[] data) throws java.io.IOException
NOTE: As from v1.3, the parent directories of the file will be created if they do not exist.
file
- the file to write todata
- the content to write to the file
java.io.IOException
- in case of an I/O errorpublic static void writeLines(java.io.File file, java.lang.String encoding, java.util.Collection lines) throws java.io.IOException
toString()
value of each item in a collection to
the specified File
line by line.
The specified character encoding and the default line ending will be used.
NOTE: As from v1.3, the parent directories of the file will be created if they do not exist.
file
- the file to write toencoding
- the encoding to use, null
means platform defaultlines
- the lines to write, null
entries produce blank lines
java.io.IOException
- in case of an I/O error
java.io.UnsupportedEncodingException
- if the encoding is not supported by the VMpublic static void writeLines(java.io.File file, java.util.Collection lines) throws java.io.IOException
toString()
value of each item in a collection to
the specified File
line by line.
The default VM encoding and the default line ending will be used.
file
- the file to write tolines
- the lines to write, null
entries produce blank lines
java.io.IOException
- in case of an I/O errorpublic static void writeLines(java.io.File file, java.lang.String encoding, java.util.Collection lines, java.lang.String lineEnding) throws java.io.IOException
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: As from v1.3, the parent directories of the file will be created if they do not exist.
file
- the file to write toencoding
- the encoding to use, null
means platform defaultlines
- the lines to write, null
entries produce blank lineslineEnding
- the line separator to use, null
is system default
java.io.IOException
- in case of an I/O error
java.io.UnsupportedEncodingException
- if the encoding is not supported by the VMpublic static void writeLines(java.io.File file, java.util.Collection lines, java.lang.String lineEnding) throws java.io.IOException
toString()
value of each item in a collection to
the specified File
line by line.
The default VM encoding and the specified line ending will be used.
file
- the file to write tolines
- the lines to write, null
entries produce blank lineslineEnding
- the line separator to use, null
is system default
java.io.IOException
- in case of an I/O errorpublic static void forceDelete(java.io.File file) throws java.io.IOException
The difference between File.delete() and this method are:
file
- file or directory to delete, must not be null
java.lang.NullPointerException
- if the directory is null
java.io.IOException
- in case deletion is unsuccessfulpublic static void forceDeleteOnExit(java.io.File file) throws java.io.IOException
file
- file or directory to delete, must not be null
java.lang.NullPointerException
- if the file is null
java.io.IOException
- in case deletion is unsuccessfulpublic static void forceMkdir(java.io.File directory) throws java.io.IOException
directory
- directory to create, must not be null
java.lang.NullPointerException
- if the directory is null
java.io.IOException
- if the directory cannot be createdpublic static long sizeOfDirectory(java.io.File directory)
directory
- directory to inspect, must not be null
java.lang.NullPointerException
- if the directory is null
public static boolean isFileNewer(java.io.File file, java.io.File reference)
File
is newer than the reference
File
.
file
- the File
of which the modification date must
be compared, must not be null
reference
- the File
of which the modification date
is used, must not be null
File
exists and has been modified more
recently than the reference File
java.lang.IllegalArgumentException
- if the file is null
java.lang.IllegalArgumentException
- if the reference file is null
or doesn't existpublic static boolean isFileNewer(java.io.File file, java.util.Date date)
File
is newer than the specified
Date
.
file
- the File
of which the modification date
must be compared, must not be null
date
- the date reference, must not be null
File
exists and has been modified
after the given Date
.
java.lang.IllegalArgumentException
- if the file is null
java.lang.IllegalArgumentException
- if the date is null
public static boolean isFileNewer(java.io.File file, long timeMillis)
File
is newer than the specified
time reference.
file
- the File
of which the modification date must
be compared, must not be null
timeMillis
- the time reference measured in milliseconds since the
epoch (00:00:00 GMT, January 1, 1970)
File
exists and has been modified after
the given time reference.
java.lang.IllegalArgumentException
- if the file is null
public static boolean isFileOlder(java.io.File file, java.io.File reference)
File
is older than the reference
File
.
file
- the File
of which the modification date must
be compared, must not be null
reference
- the File
of which the modification date
is used, must not be null
File
exists and has been modified before
the reference File
java.lang.IllegalArgumentException
- if the file is null
java.lang.IllegalArgumentException
- if the reference file is null
or doesn't existpublic static boolean isFileOlder(java.io.File file, java.util.Date date)
File
is older than the specified
Date
.
file
- the File
of which the modification date
must be compared, must not be null
date
- the date reference, must not be null
File
exists and has been modified
before the given Date
.
java.lang.IllegalArgumentException
- if the file is null
java.lang.IllegalArgumentException
- if the date is null
public static boolean isFileOlder(java.io.File file, long timeMillis)
File
is older than the specified
time reference.
file
- the File
of which the modification date must
be compared, must not be null
timeMillis
- the time reference measured in milliseconds since the
epoch (00:00:00 GMT, January 1, 1970)
File
exists and has been modified before
the given time reference.
java.lang.IllegalArgumentException
- if the file is null
public static long checksumCRC32(java.io.File file) throws java.io.IOException
file
- the file to checksum, must not be null
java.lang.NullPointerException
- if the file or checksum is null
java.lang.IllegalArgumentException
- if the file is a directory
java.io.IOException
- if an IO error occurs reading the filepublic static java.util.zip.Checksum checksum(java.io.File file, java.util.zip.Checksum checksum) throws java.io.IOException
Checksum
instance
if desired simply by reusing the same checksum object.
For example:
long csum = FileUtils.checksum(file, new CRC32()).getValue();
file
- the file to checksum, must not be null
checksum
- the checksum object to be used, must not be null
java.lang.NullPointerException
- if the file or checksum is null
java.lang.IllegalArgumentException
- if the file is a directory
java.io.IOException
- if an IO error occurs reading the file
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |