Facilities are provided in the following areas:
Origin of code: Excalibur, Alexandria, Commons-Utils
| Modifier and Type | Field and Description |
|---|---|
| public static final File[] | EMPTY_FILE_ARRAY
An empty array of type |
| public static final long | ONE_GB
The number of bytes in a gigabyte. |
| public static final long | ONE_KB
The number of bytes in a kilobyte. |
| public static final long | ONE_MB
The number of bytes in a megabyte. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static String | Returns: a human-readable display value (includes units)the number of bytes size)Returns a human-readable version of the file size, where the input represents a specific number of bytes. |
| public static Checksum | |
| public static long | Returns: the checksum valuethe file to checksum, must not be file)nullComputes the checksum of a file using the CRC32 checksum routine. |
| public static void | |
| private static void | cleanDirectoryOnExit(File
directory to clean, must not be directory)nullClean a directory without deleting it. |
| public static boolean | Returns: true if the content of the files are equal or they both don't exist, false otherwisethe first file file1, File the second file file2)Compare the contents of two files to determine if they are equal or not. |
| public static File[] | Returns: an array of java.io.Filea Collection containing java.io.File instances files)Converts a Collection containing java.io.File instanced into array representation. |
| public static void | copyDirectory(File
an existing directory to copy, must not be srcDir, File nullthe new directory, must not be destDir)nullCopies a whole directory to a new location preserving the file dates. |
| public static void | copyDirectory(File
an existing directory to copy, must not be srcDir, File nullthe new directory, must not be destDir, boolean nulltrue if the file date of the copy
should be the same as the original preserveFileDate)Copies a whole directory to a new location. |
| public static void | copyDirectoryToDirectory(File
an existing directory to copy, must not be srcDir, File nullthe directory to place the copy in, must not be destDir)nullCopies a directory to within another directory preserving the file dates. |
| public static void | |
| public static void | |
| public static void | copyFileToDirectory(File
an existing file to copy, must not be srcFile, File nullthe directory to place the copy in, must not be destDir)nullCopies a file to a directory preserving the file date. |
| public static void | copyFileToDirectory(File
an existing file to copy, must not be srcFile, File nullthe directory to place the copy in, must not be destDir, boolean nulltrue if the file date of the copy
should be the same as the original preserveFileDate)Copies a file to a directory optionally preserving the file date. |
| public static void | copyURLToFile(URL
the source, File URL to copy bytes from, must not be nullthe non-directory destination)File to write bytes to
(possibly overwriting), must not be nullCopies bytes from the URL |
| public static void | |
| private static void | deleteDirectoryOnExit(File
directory to delete, must not be directory)nullRecursively schedule directory for deletion on JVM exit. |
| private static void | doCopyDirectory(File
the validated source directory, must not be srcDir, File nullthe validated destination directory, must not be destDir, boolean nullwhether to preserve the file date preserveFileDate)Internal copy directory method. |
| private static void | doCopyFile(File
the validated source file, must not be srcFile, File nullthe validated destination file, must not be destFile, boolean nullwhether to preserve the file date preserveFileDate)Internal copy file method. |
| public static void | |
| public static void | forceDeleteOnExit(File
file or directory to delete, must not be file)nullSchedule a file to be deleted when JVM exits. |
| public static void | forceMkdir(File
directory to create, must not be directory)nullMake a directory, including any necessary but nonexistent parent directories. |
| private static void | innerListFiles(Collection<E>
the collection of files found. files, File the directory to search in. directory, IOFileFilter the filter to apply to files and directories. filter)Finds files within a given directory (and optionally its subdirectories). |
| public static boolean | Returns: true if theFile exists and has been modified more
recently than the reference Filethe file, File File of which the modification date must
be compared, must not be nullthe reference)File of which the modification date
is used, must not be nullTests if the specified |
| public static boolean | Returns: true if theFile exists and has been modified
after the given Date.the file, Date File of which the modification date
must be compared, must not be nullthe date reference, must not be date)nullTests if the specified |
| public static boolean | Returns: true if theFile exists and has been modified after
the given time reference.the file, long File of which the modification date must
be compared, must not be nullthe time reference measured in milliseconds since the
epoch (00:00:00 GMT, January 1, 1970) timeMillis)Tests if the specified |
| public static boolean | Returns: true if theFile exists and has been modified before
the reference Filethe file, File File of which the modification date must
be compared, must not be nullthe reference)File of which the modification date
is used, must not be nullTests if the specified |
| public static boolean | Returns: true if theFile exists and has been modified
before the given Date.the file, Date File of which the modification date
must be compared, must not be nullthe date reference, must not be date)nullTests if the specified |
| public static boolean | Returns: true if theFile exists and has been modified before
the given time reference.the file, long File of which the modification date must
be compared, must not be nullthe time reference measured in milliseconds since the
epoch (00:00:00 GMT, January 1, 1970) timeMillis)Tests if the specified |
| public static Iterator | Returns: an iterator of java.io.File for the matching filesthe directory to search in directory, IOFileFilter filter to apply when finding files. fileFilter, IOFileFilter optional filter to apply when finding subdirectories.
If this parameter is dirFilter)null, subdirectories will not be included in the
search. Use TrueFileFilter.INSTANCE to match all directories.Allows iteration over the files in given directory (and optionally its subdirectories). |
| public static Iterator | Returns: an iterator of java.io.File with the matching filesthe directory to search in directory, String[] an array of extensions, ex. {"java","xml"}. If this
parameter is extensions, boolean null, all files are returned.if true all subdirectories are searched as well recursive)Allows iteration over the files in a given directory (and optionally its subdirectories) which match an array of extensions. |
| public static LineIterator | Returns: an Iterator of the lines in the file, nevernullthe file to open for input, must not be file, String nullthe encoding to use, encoding)null means platform defaultReturn an Iterator for the lines in a |
| public static LineIterator | Returns: an Iterator of the lines in the file, nevernullthe file to open for input, must not be file)nullReturn an Iterator for the lines in a |
| public static Collection | Returns: an collection of java.io.File with the matching filesthe directory to search in directory, IOFileFilter filter to apply when finding files. fileFilter, IOFileFilter optional filter to apply when finding subdirectories.
If this parameter is dirFilter)null, subdirectories will not be included in the
search. Use TrueFileFilter.INSTANCE to match all directories.Finds files within a given directory (and optionally its subdirectories). |
| public static Collection | Returns: an collection of java.io.File with the matching filesthe directory to search in directory, String[] an array of extensions, ex. {"java","xml"}. If this
parameter is extensions, boolean null, all files are returned.if true all subdirectories are searched as well recursive)Finds files within a given directory (and optionally its subdirectories) which match an array of extensions. |
| public static FileInputStream | Returns: a newFileInputStream for the specified filethe file to open for input, must not be file)nullOpens a |
| public static FileOutputStream | Returns: a newFileOutputStream for the specified filethe file to open for output, must not be file)nullOpens a |
| public static byte[] | Returns: the file contents, nevernullthe file to read, must not be file)nullReads the contents of a file into a byte array. |
| public static String | Returns: the file contents, nevernullthe file to read, must not be file, String nullthe encoding to use, encoding)null means platform defaultReads the contents of a file into a String. |
| public static String | Returns: the file contents, nevernullthe file to read, must not be file)nullReads the contents of a file into a String using the default encoding for the VM. |
| public static List | |
| public static List | |
| public static long | Returns: size of directory in bytes, 0 if directory is security restricteddirectory to inspect, must not be directory)nullRecursively count size of a directory (sum of the length of all files). |
| public static File | |
| public static File[] | |
| private static String[] | Returns: an array of suffixes. Format: {".java", ".xml"}an array of extensions. Format: {"java", "xml"} extensions)Converts an array of file extensions to suffixes for use with IOFileFilters. |
| public static void | |
| public static URL[] | |
| public static boolean | |
| public static void | writeByteArrayToFile(File
the file to write to file, byte[] the content to write to the file data)Writes a byte array to a file creating the file if it does not exist. |
| public static void | writeLines(File
the file to write to file, String the encoding to use, encoding, Collection<E> null means platform defaultthe lines to write, lines)null entries produce blank linesWrites the |
| public static void | writeLines(File
the file to write to file, Collection<E> the lines to write, lines)null entries produce blank linesWrites the |
| public static void | writeLines(File
the file to write to file, String the encoding to use, encoding, Collection<E> null means platform defaultthe lines to write, lines, String null entries produce blank linesthe line separator to use, lineEnding)null is system defaultWrites the |
| public static void | writeLines(File
the file to write to file, Collection<E> the lines to write, lines, String null entries produce blank linesthe line separator to use, lineEnding)null is system defaultWrites the |
| public static void | writeStringToFile(File
the file to write file, String the content to write to the file data, String the encoding to use, encoding)null means platform defaultWrites a String to a file creating the file if it does not exist. |
| public static void | writeStringToFile(File
the file to write file, String the content to write to the file data)Writes a String to a file creating the file if it does not exist using the default encoding for the VM. |