public class FileUtil extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ROOT |
static java.lang.String |
ROOT_UNIX |
static java.lang.String |
ROOT_WINDOWS |
static java.lang.String |
ROOT_WINDOWS_NETWORK |
| Modifier and Type | Method and Description |
|---|---|
static java.util.List<java.io.File> |
expandFiles(java.io.File currentDirectory,
java.lang.String... paths)
Expands files if necessary, meaning that input files with wildcards are
expanded.
|
static java.util.List<java.io.File> |
expandFiles(java.lang.String... paths)
Expands files if necessary, meaning that input files with wildcards are
expanded.
|
static java.io.File |
getDirectoryOfClassFile(java.lang.Class<?> clazz)
This method returns the parent directory of a given class.
|
static java.io.File |
getDirectoryOfClassFile(java.lang.String className)
This method returns the parent directory of a given class.
|
static java.io.FilenameFilter |
getFileNameFilter(java.lang.String name)
Returns a file name filter for the specified name.
|
static java.io.File |
getOutputDirectoryGivenClass(java.lang.Class<?> clazz)
This method returns the output directory of a given class.
|
static java.util.List<java.lang.String> |
getPathElements(java.io.File file)
Returns all path elements of the given
file. |
static java.lang.String |
getRelativePath(java.io.File root,
java.io.File file)
Returns the path of the given
file relative to the given
root. |
static java.io.File |
getUserDir()
Returns the user's current working directory taken from the system
property "user.dir".
|
static boolean |
isWildcardFileName(java.lang.String name)
Returns true if the given name or path contains unescaped wildcard
characters.
|
static java.io.File |
toAbsoluteFile(java.io.File currentDirectory,
java.io.File file)
Returns an absolute file for the given input file, resolving relative
paths on the basis of the given
currentDirectory. |
static java.util.List<java.io.File> |
toList(java.io.File... files)
Returns the specified files in a new mutable array list.
|
public static final java.lang.String ROOT_UNIX
public static final java.lang.String ROOT_WINDOWS
public static final java.lang.String ROOT_WINDOWS_NETWORK
public static final java.lang.String ROOT
public static java.io.File getUserDir()
System.getProperties()public static java.util.List<java.io.File> toList(java.io.File... files)
Arrays.asList(Object...) but the returned list is expandable.files - the files to add to a new listpublic static java.lang.String getRelativePath(java.io.File root, java.io.File file)
file relative to the given
root.
The relative path is evaluated as follows:
root is the same as file, "." is returnedroot is the direct parent directory of file, the
simple file name is returnedroot is a non-direct parent directory of file, the
relative path from root to file is returnedroot is not parent directory of file, the relative
path is the path from root to the common ancestor and then to
fileroot is not parent directory of file and the only
common ancestor of the two is the root directory, the absolute path of
file is returnedroot - the root directory for the relative pathfile - the file whose path should be returnedfile relative to rootpublic static java.io.File toAbsoluteFile(java.io.File currentDirectory, java.io.File file)
currentDirectory. If the given
file represents an absolute path or a variable, it is returned
unchanged. If currentDirectory==null,
File.getAbsoluteFile() is returned.currentDirectory - the current directoryfile - the file to be returned as absolute filecurrentDirectory as basis for relative pathsFile.isAbsolute(),
Arg.isVariable(String),
File.getAbsoluteFile()public static java.util.List<java.lang.String> getPathElements(java.io.File file)
file. The absolute path of
the file is used to evaluate the path elements.
For instance, a list with the 3 elements "var", "tmp", "out.txt" is returned for an input file "/var/tmp/out.txt".
file - the file whose path elements should be returnedfilepublic static java.util.List<java.io.File> expandFiles(java.lang.String... paths)
files list contains no wildcard, the
files are simply returned; all wildcard files are expanded.paths - the file paths, possibly containing wildcard partspublic static java.util.List<java.io.File> expandFiles(java.io.File currentDirectory, java.lang.String... paths)
files list contains no wildcard, the
files are simply returned; all wildcard files are expanded. The given
current directory serves as basis for all relative paths.currentDirectory - the basis for all relative pathspaths - the file paths, possibly containing wildcard partspublic static java.io.FilenameFilter getFileNameFilter(java.lang.String name)
The wildcards "*" and "?" are supported. "*" stands for any character repeated 0 to many times, "?" for exactly one arbitrary character. Both characters can be escaped with a preceding backslash character \ (Unix and MAC) or % character (Windows).
name - the name or pattern without pathpublic static boolean isWildcardFileName(java.lang.String name)
name - the name or pathpublic static java.io.File getOutputDirectoryGivenClass(java.lang.Class<?> clazz)
clazz - public static java.io.File getDirectoryOfClassFile(java.lang.Class<?> clazz)
clazz - public static java.io.File getDirectoryOfClassFile(java.lang.String className)
className - fully qualified class nameCopyright © 2021. All Rights Reserved.