public class FileUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static long |
FAT_FILE_TIMESTAMP_GRANULARITY
The granularity of timestamps under FAT.
|
static long |
UNIX_FILE_TIMESTAMP_GRANULARITY
The granularity of timestamps under Unix.
|
| Constructor and Description |
|---|
FileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
copyFile(File sourceFile,
File destFile,
boolean overwrite,
boolean preserveLastModified)
Convenience method to copy a file from a source to a
destination specifying if token filtering must be used, if
filter chains must be used, if source files may overwrite
newer destination files and the last modified time of
destFile file should be made equal
to the last modified time of sourceFile. |
static void |
copyFile(String sourceFile,
String destFile,
boolean overwrite,
boolean preserveLastModified)
Convenience method to copy a file from a source to a destination.
|
static File |
createTempDirectory(String prefix,
File directory)
Create a temporary directory.
|
static long |
getFileTimestampGranularity()
Get the granularity of file timestamps.
|
static File |
getParentFile(File f)
This was originally an emulation of
File.getParentFile() for JDK 1.1,
but it is now implemented using that method (Ant 1.6.3 onwards). |
static boolean |
isSymbolicLink(File parent,
String name)
Checks whether a given file is a symbolic link.
|
static String |
removeLeadingPath(File leading,
File path)
Removes a leading path from a second path.
|
static File |
resolveFile(File file,
String filename)
Interpret the filename as a file relative to the given file
unless the filename already represents an absolute filename.
|
public static final long FAT_FILE_TIMESTAMP_GRANULARITY
public static final long UNIX_FILE_TIMESTAMP_GRANULARITY
public static void copyFile(String sourceFile, String destFile, boolean overwrite, boolean preserveLastModified) throws IOException
sourceFile - Name of file to copy from.
Must not be null.destFile - Name of file to copy to.
Must not be null.IOException - if the copying fails.public static void copyFile(File sourceFile, File destFile, boolean overwrite, boolean preserveLastModified) throws IOException
destFile file should be made equal
to the last modified time of sourceFile.sourceFile - the file to copy from.
Must not be null.destFile - the file to copy to.
Must not be null.overwrite - Whether or not the destination file should be
overwritten if it already exists.preserveLastModified - Whether or not the last modified time of
the resulting file should be set to that
of the source file.IOException - if the copying fails.public static File resolveFile(File file, String filename) throws Exception
file - the "reference" file for relative paths. This
instance must be an absolute file and must not contain
"./" or "../" sequences (same for \ instead
of /). If it is null, this call is equivalent to
new java.io.File(filename).filename - a file name.Exceptionpublic static File getParentFile(File f)
File.getParentFile() for JDK 1.1,
but it is now implemented using that method (Ant 1.6.3 onwards).f - the file whose parent is required.public static boolean isSymbolicLink(File parent, String name) throws IOException
It doesn't really test for symbolic links but whether the canonical and absolute paths of the file are identical--this may lead to false positives on some platforms.
parent - the parent directory of the file to testname - the name of the file to test.IOException - on error.public static String removeLeadingPath(File leading, File path) throws Exception
leading - The leading path, must not be null, must be absolute.path - The path to remove from, must not be null, must be absolute.Exceptionpublic static long getFileTimestampGranularity()
public static File createTempDirectory(String prefix, File directory) throws IOException
prefix - the prefix string to be used in generating the directory's
name; must be at least three characters longdirectory - the directory in which the file is to be created, or
null if the default temporary-file directory is to be usedIOException - if the creation of the directory failsCopyright © 2001–2025. All rights reserved.