获取java 类的路径
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());
}
}
相关文档:
1.Java学习网站:
Java中文世界论坛 http://www.chinajavaworld.com/index.jspa
Java世纪网 http://www.java2000.net/
Java 中文站 http://www.java-cn.com/
Java学习室 ......
下面是常用处理日期的方法,希望对大家有用!
在我 ......
xml文件:
Xml代码
<?xml version="1.0" encoding="GB2312"?>
<RESULT>
<VALUE>
<NO>A1234</NO>
<ADDR>河南省郑州市</ADDR>
</VALUE>&nbs ......
XML文件 book.xml
<book>
<person>
<first>Kiran</first>
<last>Pai</last>
<age>22</age>
</person>
<person>
<first>Bill</first>
<last>Gates</last>
<age>46</age>
</person>
<person>
&l ......
归纳一些网上取JAVA路径的方法:
注明:如果从ANT启动程序,this.getClass().getResource("")取出来的比较怪,直接用JAVA命令行调试就可成功。
得到classpath和当前类的绝对路径的一些方法
获得CLASSPATH之外路径的方法:
URL base = this.getClass().getResource(""); //先获得本类的所在位置,如/home/popeye/ ......