Java 获取当前类文件所在的路径
2018-07-20 来源:open-open
import java.net.URL;
import org.apache.commons.lang.StringUtils;
/**
* 类路径获取
*/
public class ResourcePathTester {
public static void main(String[] args) {
System.out.println(getResourcePath());
}
private static String getResourcePath() {
String className = ResourcePathTester.class.getName();
String classNamePath = className.replace(".", "/") + ".class";
URL is = ResourcePathTester.class.getClassLoader().getResource(classNamePath);
String path = is.getFile();
path = StringUtils.replace(path, "%20", " ");
return StringUtils.removeStart(path, "/");
}
}
标签: ssl
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:Java计算时间差
最新资讯
热门推荐