public class FilePath extends Object
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static String |
BACKSLASH |
|
static String |
BACKSLASHDOT |
|
static String |
DOT |
|
static String |
DOTBACKSLASH |
|
static String |
DOTSLASH |
|
static String |
EMPTY |
|
static Pattern |
ONLY_DOT_PATTERN |
|
static String |
PARENT_DIR |
|
static String |
ROOT |
|
static String |
SLASH |
|
static Pattern |
SLASH_PATTERN |
|
static String |
SLASHDOT |
|
static String |
TWOBACKSLASH |
| 构造器 | 说明 |
|---|---|
FilePath() |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static String |
addHeadDotSlash(String originPath) |
Merge multi
"/" and "./" to one first, and then add "./" to head. |
static String |
addHeadDotSlash(String originPath,
boolean isNeedMerge) |
Add
"./" to head. |
static String |
addHeadSlash(String originPath) |
Merge multi
"/" and "./" to one first, and then add "/" to head. |
static String |
addHeadSlash(String originPath,
boolean isNeedMerge) |
Add
"/" to head. |
static String |
addTailSlash(String originPath) |
Merge multi
"/" and "./" to one first, and then add tail "/". |
static String |
addTailSlash(String originPath,
boolean isNeedMerge) |
Add tail
"/". |
static String |
backslashToSlash(String originPath) |
For Windows systems, transform
'\' to '/', and merge multi '/' to one in file path. |
private static String |
concatPath(boolean isWin,
String firstPath,
String... subPaths) |
Concat paths.
|
static String |
ext(String fileName) |
Get file extension from filename.
|
static String |
extNoDot(String fileName) |
Get file extension without dot from filename.
|
static String[] |
exts(String fileName) |
获取文件名的后缀名数组,用于拼接后缀名
|
private static PathInfo |
getPathInfo(String filePath,
SeparatorType separatorType) |
获取PathInfo
注: Win和Unix-like系统 . 与 .. 都代表文件夹,无法创建重名的文件;Win下无法创建只包含 . 的文件或文件夹;Win下无法创建包含 / 或 \ 的文件或文件夹;Unix-like下无法创建包含 / 的文件或文件夹,可以创建只包含 \ 的文件或文件夹(mkdir \\ 或 touch \\) |
static PathInfo |
info(String filePath) |
PathInfo for Unix-like systems.
|
static PathInfo |
infoAuto(String filePath) |
The system-dependent for getting PathInfo.
|
static PathInfo |
infoAutoWin(String filePath) |
The system-dependent for getting PathInfo.
|
static PathInfo |
infoSlash(String filePath) |
PathInfo for Windows systems.
|
static PathInfo |
infoWin(String filePath) |
PathInfo for Windows systems.
|
static String |
mergeDotBackslash(String originPath) |
Merge multi
'.\' to one. |
static String |
mergeDotSlash(String originPath) |
Merge multi
'./' to one. |
static String |
mergeRepeated(String originPath) |
Merge multi
'/' to one first, and then merge multi "./" to one. |
static String |
mergeSlash(String originPath,
boolean whetherMergeSlash) |
Merge multi
'/' or '\' to one. |
static String |
path(String firstPath,
String... subPaths) |
Path for Unix-like systems. it will use
'/' as files separator. |
static String |
pathAuto(String firstPath,
String... subPaths) |
The system-dependent for concat paths.
|
static String |
pathAutoWin(String firstPath,
String... subPaths) |
The system-dependent for concat paths.
|
static String |
pathSlash(String firstPath,
String... subPaths) |
Path for Windows systems. it will use
'/' as files separator,
and will transform all '\' to '/'. |
static String |
pathWin(String firstPath,
String... subPaths) |
Path for Windows systems. it will use
'\' as files separator,
and will transform all '/' to '\'. |
static String |
rmHeadDotSlash(String originPath) |
Merge multi
"/" and "./" to one first, and then remove "./" at the head. |
static String |
rmHeadDotSlash(String originPath,
boolean isNeedMerge) |
Remove
"./" at the head. |
static String |
rmHeadSlash(String originPath) |
Merge multi
"/" and "./" to one first, and then remove "/" at the head. |
static String |
rmHeadSlash(String originPath,
boolean isNeedMerge) |
Remove
"/" at the head. |
static String |
rmTailSlash(String originPath) |
Merge multi
"/" and "./" to one first, and then remove tail "/". |
static String |
rmTailSlash(String originPath,
boolean isNeedMerge) |
Remove tail
"/". |
static String |
rmTailSlashDot(String originPath) |
Merge multi
"/" and "./" to one first, and then remove tail "/.". |
static String |
rmTailSlashDot(String originPath,
boolean isNeedMerge) |
Remove tail
"/.". |
static String |
slashToBackslash(String originPath) |
For Windows systems, transform
'/' to '\', and merge multi '\' to one in file path. |
private static void |
verifyParams(String firstPath,
String... subPaths) |
Verify params.
|
public static final Pattern SLASH_PATTERN
public static final Pattern ONLY_DOT_PATTERN
public static String path(String firstPath, String... subPaths)
'/' as files separator. '/' 作为文件之间的分隔符。
且 '\' 在Unix-like系统路径中作为转义字符使用,所以不能转成 '/'。
FilePath.path("./a", "b", "./c/", "/d") returns "./a/b/c/d"
FilePath.path("./", "./", "//", "/.") returns "."
firstPath - firstPathsubPaths - subPathspublic static String pathWin(String firstPath, String... subPaths)
'\' as files separator,
and will transform all '/' to '\'. '\' 作为文件之间的分隔符,会将所有 '/' 转换成 '\'。
FilePath.pathWin("./a", "\\\b", "\\\./c", "/d") returns ".\a\b\c\d"
FilePath.pathWin("./.", "./") returns "."
firstPath - firstPathsubPaths - subPathspublic static String pathSlash(String firstPath, String... subPaths)
'/' as files separator,
and will transform all '\' to '/'. '/' 作为文件之间的分隔符,会将所有 '\' 转换成 '/'。
FilePath.pathSlash("./a", "\\\b", "\\\./c", "/d") returns "./a/b/c/d"
FilePath.pathSlash("/", "./") returns "/"
firstPath - firstPathsubPaths - subPathsprivate static String concatPath(boolean isWin, String firstPath, String... subPaths)
isWin - is Windows path or notfirstPath - firstPathsubPaths - subPathsnull when firstPath is null or there is null value in subPaths.public static String pathAuto(String firstPath, String... subPaths)
path(String, String...); pathSlash(String, String...). path(String, String...);pathSlash(String, String...)。firstPath - firstPathsubPaths - subPathspublic static String pathAutoWin(String firstPath, String... subPaths)
path(String, String...); pathWin(String, String...). path(String, String...);pathWin(String, String...)。firstPath - firstPathsubPaths - subPathspublic static PathInfo info(String filePath)
SeparatorType.SLASH.filePath - 文件路径public static PathInfo infoWin(String filePath)
SeparatorType.BACKSLASH.filePath - 文件路径public static PathInfo infoSlash(String filePath)
SeparatorType.WIN_SLASH.filePath - 文件路径public static PathInfo infoAuto(String filePath)
filePath - 文件路径public static PathInfo infoAutoWin(String filePath)
filePath - 文件路径private static PathInfo getPathInfo(String filePath, SeparatorType separatorType)
. 与 .. 都代表文件夹,无法创建重名的文件;. 的文件或文件夹;/ 或 \ 的文件或文件夹;/ 的文件或文件夹,可以创建只包含 \ 的文件或文件夹(mkdir \\ 或 touch \\)filePath - filePathseparatorType - separatorTypepublic static String addHeadDotSlash(String originPath)
"/" and "./" to one first, and then add "./" to head. "/"和"./",再添加头部的 "./"originPath - originPathpublic static String addHeadDotSlash(String originPath, boolean isNeedMerge)
"./" to head. "./"originPath - originPathisNeedMerge - is need merge "/" and "./" firstpublic static String rmHeadDotSlash(String originPath)
"/" and "./" to one first, and then remove "./" at the head. "/"和"./",再删除头部的 "./"originPath - originPathpublic static String rmHeadDotSlash(String originPath, boolean isNeedMerge)
"./" at the head. "./"originPath - originPathisNeedMerge - is need merge "/" and "./" firstpublic static String rmTailSlashDot(String originPath)
"/" and "./" to one first, and then remove tail "/.". "/"和"./",再删除尾部的 "/."originPath - originPathpublic static String rmTailSlashDot(String originPath, boolean isNeedMerge)
"/.". "/."originPath - originPathisNeedMerge - is need merge "/" and "./" firstpublic static String rmTailSlash(String originPath)
"/" and "./" to one first, and then remove tail "/". "/"和"./",再去除路径尾部 '/'originPath - originPathpublic static String rmTailSlash(String originPath, boolean isNeedMerge)
"/". '/'originPath - originPathisNeedMerge - is need merge "/" and "./" firstpublic static String rmHeadSlash(String originPath)
"/" and "./" to one first, and then remove "/" at the head. "/"和"./",再去除路径头部 '/'originPath - originPathpublic static String rmHeadSlash(String originPath, boolean isNeedMerge)
"/" at the head. '/'originPath - originPathisNeedMerge - is need merge "/" and "./" firstpublic static String addHeadSlash(String originPath)
"/" and "./" to one first, and then add "/" to head. "/"和"./",再添加头部 '/'originPath - originPathpublic static String addHeadSlash(String originPath, boolean isNeedMerge)
"/" to head. '/'originPath - originPathisNeedMerge - is need merge "/" and "./" firstpublic static String addTailSlash(String originPath)
"/" and "./" to one first, and then add tail "/". "/"和"./",再添加尾部 '/'originPath - originPathpublic static String addTailSlash(String originPath, boolean isNeedMerge)
"/". '/'originPath - originPathisNeedMerge - is need merge "/" and "./" firstpublic static String backslashToSlash(String originPath)
'\' to '/', and merge multi '/' to one in file path. '\' 转成 '/',并合并多个重复的'/'。originPath - originPathpublic static String slashToBackslash(String originPath)
'/' to '\', and merge multi '\' to one in file path. '/' 转成 '\',并合并多个重复的'\'。originPath - originPathpublic static String mergeRepeated(String originPath)
'/' to one first, and then merge multi "./" to one. '/',再去除重复的 "./"。originPath - originPathpublic static String mergeSlash(String originPath, boolean whetherMergeSlash)
'/' or '\' to one. '/' 或 '\' 成一个。originPath - originPathwhetherMergeSlash - if true, merge '/'; otherwise, merge '\'public static String mergeDotSlash(String originPath)
'./' to one. './' 成一个。originPath - originPathpublic static String mergeDotBackslash(String originPath)
'.\' to one. '.\' 成一个。originPath - originPathpublic static String[] exts(String fileName)
fileName - 文件名public static String ext(String fileName)
fileName - 文件名.txt, .csvpublic static String extNoDot(String fileName)
fileName - 文件名txt, csvCopyright © 2023. All rights reserved.