public final class PathTools
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
PathTools.PathParts |
Modifier and Type | Field and Description |
---|---|
private static java.lang.String[] |
localFolderPaths |
Modifier | Constructor and Description |
---|---|
private |
PathTools() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addSlash(java.lang.String path) |
static java.lang.String |
changeExtension(java.lang.String file,
java.lang.String extension) |
static java.io.File |
fileFromPath(java.lang.String path) |
static java.io.File |
fileFromPath(java.lang.String path,
boolean mustExist) |
static java.io.File |
findLocalPath(java.lang.Class refType,
java.lang.String name,
java.lang.String... tryPaths) |
static java.io.File |
findLocalPath(java.lang.String name) |
static java.lang.String |
getAppPath(java.lang.Class referenceClass)
Gets the absolute path to the directory containing the class file for referenceClass.
|
static java.lang.String |
getBaseName(java.lang.String fullName)
Gets the base name of the file -- i.e.
|
static java.lang.String |
getBaseName(java.lang.String fullName,
boolean allowMultiDotExtensions)
Gets the base name of the file -- i.e.
|
static java.lang.String |
getCanonicalPath(java.lang.String path)
Get the canonical form of a file-system path by:
Converting it to unix format (if Windows)
Replacing
// with /
Replacing /./ with /
Replacing dirname/../ with /
|
static java.lang.String |
getCanonicalPath(java.lang.String path,
boolean addEndSlash,
boolean removeEndSlash,
boolean removeStartSlash,
boolean removeDotSlashAtStart)
Get the canonical form of a file-system path by:
Converting it to unix format (if Windows)
Removing starting slashes (if
removeStartSlash is true)
Adding an ending slash (if addEndSlash is true}
Removing an ending slash (if removeEndSlash is true
Replacing // with /
Replacing /./ with /
Replacing dirname/../ with /
Removing ./ at the start of a path (if removeDotSlashAtStart is true)
|
static java.lang.String |
getExt(java.lang.String fullName)
Gets the extension of the file including the preceding dot (.)
If the file name contains multiple dot (.) characters, the extension is defined as the segment starting with
the final dot.
|
static java.lang.String |
getExt(java.lang.String fullName,
boolean allowMultiDotExtensions)
Gets the extension of the file including the preceding dot (.)
|
static java.io.File |
getHomeDir() |
static PathTools.PathParts |
getParts(java.lang.String fullFilePath) |
static PathTools.PathParts |
getParts(java.lang.String fullFilePath,
boolean splitDirs) |
static PathTools.PathParts |
getParts(java.lang.String fullFilePath,
boolean splitDirs,
boolean allowMultiDotExtensions) |
static java.lang.String |
getPath(java.lang.String fullName)
Get the full parent directory path, including the final slash.
|
static java.util.List<java.io.File> |
listFiles(java.lang.String dirPath,
java.lang.String filter) |
static boolean |
verifyWritable(java.io.File file)
Verify that a directory is writeable by writing a new file (and then deleting it).
|
public static java.lang.String addSlash(java.lang.String path)
public static java.lang.String changeExtension(java.lang.String file, java.lang.String extension)
public static java.io.File fileFromPath(java.lang.String path)
public static java.io.File fileFromPath(java.lang.String path, boolean mustExist)
public static java.io.File findLocalPath(java.lang.Class refType, java.lang.String name, java.lang.String... tryPaths)
public static java.io.File findLocalPath(java.lang.String name)
@Nullable public static java.lang.String getAppPath(java.lang.Class referenceClass)
null
if security restrictions do not permit resolution of paths.public static java.lang.String getBaseName(java.lang.String fullName)
fullName
- The full file name or path.getBaseName(String, boolean)
public static java.lang.String getBaseName(java.lang.String fullName, boolean allowMultiDotExtensions)
fullName
- The full file name or path.allowMultiDotExtensions
- If true, the extension starts at the first dot (.) encountered, which
means the resulting base name will never contain any dots.
If false, the extension starts at the last dot, so the base name will
contain all dots except the final one.public static java.lang.String getCanonicalPath(java.lang.String path)
//
with /
/./
with /
dirname/../
with /
path
- The path to canonicalizegetCanonicalPath(String, boolean, boolean, boolean, boolean)
public static java.lang.String getCanonicalPath(java.lang.String path, boolean addEndSlash, boolean removeEndSlash, boolean removeStartSlash, boolean removeDotSlashAtStart)
removeStartSlash
is true)addEndSlash
is true}removeEndSlash
is true//
with /
/./
with /
dirname/../
with /
./
at the start of a path (if removeDotSlashAtStart
is true)path
- The path to canonicalizeaddEndSlash
- If true, any slashes at the end of the path will be removed. i.e. path/
becomes path
removeEndSlash
- If true any path not ending with a slash will have one appended. i.e. path
becomes path/
removeStartSlash
- If true, any slashes at the beginning of the path will be removed. i.e. /path
becomes path
removeDotSlashAtStart
- If this is true and the path starts with ./
, it will be removed. i.e. ./path
becomes path
public static java.lang.String getExt(java.lang.String fullName)
fullName
- The full file name or path.public static java.lang.String getExt(java.lang.String fullName, boolean allowMultiDotExtensions)
fullName
- The full file name or path.allowMultiDotExtensions
- If true, the extension starts at the first dot (.) encountered in
the file name, which means the resulting extension may contain more than one dot.
If false, the extension starts at the last dot, so the extension will
either be empty (if the file has no extension) or it will contain exactly one
dot as its first character.public static java.io.File getHomeDir()
public static PathTools.PathParts getParts(java.lang.String fullFilePath)
public static PathTools.PathParts getParts(java.lang.String fullFilePath, boolean splitDirs)
public static PathTools.PathParts getParts(java.lang.String fullFilePath, boolean splitDirs, boolean allowMultiDotExtensions)
public static java.lang.String getPath(java.lang.String fullName)
/path/to/fileName.ext | --> | /path/to/ |
/fileName.ext | --> | / |
C:\Windows\System32 | --> | C:\Windows\ |
images\banana.jpg | --> | images\ |
HelloWorld.txt | --> | (empty) |
fullName
- The full path to the file.\
or /
.public static java.util.List<java.io.File> listFiles(java.lang.String dirPath, @NotNull java.lang.String filter)
public static boolean verifyWritable(java.io.File file)
file
-