public class PathUtils extends Object
| 构造器和说明 |
|---|
PathUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
cleanJarPath(String original)
当打包成jar包后,通过
class.getResource或
ClassLoader.getResource获取路径会类似这样:
jar:file:/c:/myapp/myapp.jar! |
static String |
cleanPath(String path)
Normalize the path by suppressing sequences like "path/.." and inner
simple dots.
|
static URL |
cleanPath(URL originalUrl)
Normalize the path by suppressing sequences like "path/.." and inner
simple dots.
|
static String |
getAppDir(Class<?> clazz)
获取程序启动的classpath路径(文件系统),如果是jar包则返回jar包所在的目录路径。
|
static URL |
getCodeLocation(Class<?> clazz)
获取代码所在的URL,即class文件所在的路径。
|
static String |
getRealPath(String locationPattern)
获取平台相关的绝对路径。
|
static String |
getRealPath(URL originalUrl)
获取平台相关的绝对路径。
|
public static String cleanPath(String path)
The result is convenient for path comparison. For other uses, notice that Windows separators ("\") are replaced by simple slashes.
path - the original pathpublic static String cleanJarPath(String original)
class.getResource或
ClassLoader.getResource获取路径会类似这样:
jar:file:/c:/myapp/myapp.jar!/path...清理后为:file:/c:/myapp/path...original - public static URL cleanPath(URL originalUrl) throws MalformedURLException, URISyntaxException
The result is convenient for path comparison. For other uses, notice that Windows separators ("\") are replaced by simple slashes.
originalUrl - the url with original pathMalformedURLExceptionURISyntaxExceptionpublic static String getRealPath(URL originalUrl)
windows下的路径分割符为"\",Unix*下为"/"。
originalUrl - URLpublic static String getRealPath(String locationPattern) throws IOException, URISyntaxException
locationPattern - ResourceConstantsIOExceptionURISyntaxExceptionpublic static String getAppDir(Class<?> clazz)
Copyright © 2015 Baifendian Corporation. All rights reserved.