public class Path {
//get class absolute address
public String getPath() {
String classPath = getClass().getName();
if (classPath.indexOf(".") != -1) {
classPath = classPath.substring(classPath.lastIndexOf(".") + 1,
classPath.length());
}
classPath = getClass().getResource(classPath + ".class").toString();
classPath = classPath.substring(classPath.indexOf('/') + 1, classPath
.lastIndexOf('/')+1);
return classPath;
}
public static void main(String[] args)
{
System.out.println(new Path().getPath());
}
}
获取java 类的路径
最新推荐文章于 2024-08-16 09:59:15 发布

498

被折叠的 条评论
为什么被折叠?



