public final class FileUtils
extends java.lang.Object
File
instances.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CURRENT_DIRECTORY
The relative file path to the current directory.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
backOneDirectory(java.lang.String fileIdentifier)
Returns the given file system path minus its last element
|
static boolean |
copyRecursively(java.io.File source,
java.io.File destination,
boolean deleteDestinationOnExit)
Copies the specified source directory to the destination.
|
static boolean |
deleteRecursively(java.io.File file)
Deletes the specified
File . |
static boolean |
denotesAbsolutePath(java.lang.String fileName)
Checks if the provided fileName denotes an absolute path on the file system.
|
static java.lang.String |
ensureTrailingSeparator(java.lang.String path)
Ensures that the given path has exactly one trailing
File.separator |
static java.lang.String |
getCanonicalPath(java.io.File file)
Returns the canonical path of the given
File . |
static java.io.File |
getFile(java.lang.Class<?> loadingClass,
java.lang.String filename)
Loads the given file from the classpath.
|
static java.lang.String |
getFileSeparatorAsRegex()
Returns the platform-specific file separator as a regular expression.
|
static java.lang.String |
getFirstDirectory(java.lang.String fileIdentifier)
Returns the part of the given path that represents a directory, in other
words the given path if it's already a directory, or the parent directory
if it's a file.
|
static java.io.InputStream |
getInputStream(java.lang.Class<?> loadingClass,
java.lang.String filename)
Loads the given file from the classpath.
|
static java.lang.String |
getPath(java.lang.Class<?> loadingClass,
java.lang.String relativeFilename)
Determines the path to the requested file, relative to the given class.
|
static java.lang.String |
getSystemDependentPath(java.util.Collection<java.lang.String> pathElements)
Returns an operating-system-dependent path consisting of the given
elements, separated by
File.separator . |
static java.lang.String |
getSystemDependentPath(java.lang.String... pathElements)
Returns an operating-system-dependent path consisting of the given
elements, separated by
File.separator . |
static boolean |
matchesAntPath(java.lang.String antPattern,
java.lang.String canonicalPath)
Indicates whether the given canonical path matches the given Ant-style pattern
|
static java.lang.String |
read(java.io.File file)
Returns the contents of the given File as a String.
|
static java.lang.String |
readBanner(java.lang.Class<?> loadingClass,
java.lang.String resourceName)
Reads a banner from the given resource.
|
static java.lang.String |
readBanner(java.io.Reader reader)
Reads a banner from the given resource.
|
static java.lang.String |
removeLeadingAndTrailingSeparators(java.lang.String path)
Removes any leading or trailing
File.separator s from the given path. |
static java.lang.String |
removeTrailingSeparator(java.lang.String path)
Removes any trailing
File.separator s from the given path |
public static final java.lang.String CURRENT_DIRECTORY
public static boolean deleteRecursively(java.io.File file)
File
.
If the File
refers to a directory, any contents of that directory (including other directories)
are also deleted.
If the File
does not already exist, this method immediately returns true.
file
- to delete (required; the file may or may not exist)public static boolean copyRecursively(java.io.File source, java.io.File destination, boolean deleteDestinationOnExit)
Both the source must exist. If the destination does not already exist, it will be created. If the destination does exist, it must be a directory (not a file).
source
- the already-existing source directory (required)destination
- the destination directory (required)deleteDestinationOnExit
- indicates whether to mark any created destinations for deletion on exitpublic static boolean denotesAbsolutePath(java.lang.String fileName)
fileName
- name of a file, which could be an absolute pathpublic static java.lang.String getFirstDirectory(java.lang.String fileIdentifier)
fileIdentifier
- the path to parse (required)public static java.lang.String backOneDirectory(java.lang.String fileIdentifier)
fileIdentifier
- public static java.lang.String removeTrailingSeparator(java.lang.String path)
File.separator
s from the given pathpath
- the path to modify (can be null
)public static boolean matchesAntPath(java.lang.String antPattern, java.lang.String canonicalPath)
antPattern
- the pattern to check against (can't be blank)canonicalPath
- the path to check (can't be blank)public static java.lang.String removeLeadingAndTrailingSeparators(java.lang.String path)
File.separator
s from the given path.path
- the path to modify (can be null
)null
if null
was givenpublic static java.lang.String ensureTrailingSeparator(java.lang.String path)
File.separator
path
- the path to modify (can't be null
)public static java.lang.String getSystemDependentPath(java.lang.String... pathElements)
File.separator
.pathElements
- the path elements from uppermost downwards (can't be empty)public static java.lang.String getSystemDependentPath(java.util.Collection<java.lang.String> pathElements)
File.separator
.pathElements
- the path elements from uppermost downwards (can't be empty)public static java.lang.String getCanonicalPath(java.io.File file)
File
.file
- the file for which to find the canonical path (can be null
)null
if a null
file is givenpublic static java.lang.String getFileSeparatorAsRegex()
public static java.lang.String getPath(java.lang.Class<?> loadingClass, java.lang.String relativeFilename)
loadingClass
- the class to whose package the given file is relative (required)relativeFilename
- the name of the file relative to that package (required)null
)public static java.io.File getFile(java.lang.Class<?> loadingClass, java.lang.String filename)
loadingClass
- the class from whose package to load the file (required)filename
- the name of the file to load, relative to that package (required)null
)java.lang.IllegalArgumentException
- if the given file cannot be foundpublic static java.io.InputStream getInputStream(java.lang.Class<?> loadingClass, java.lang.String filename)
loadingClass
- the class from whose package to load the file (required)filename
- the name of the file to load, relative to that package (required)null
)java.lang.IllegalArgumentException
- if the given file cannot be foundpublic static java.lang.String readBanner(java.io.Reader reader)
public static java.lang.String readBanner(java.lang.Class<?> loadingClass, java.lang.String resourceName)
public static java.lang.String read(java.io.File file)
file
- the file to read from (must be an existing file)java.lang.IllegalStateException
- in case of I/O errors