user.dir User's current working directory
String s = System.getProperty("user.dir");
String s = System.getProperty("user.dir");
解决方案 »
- java类的功能太多,把功能分散给2个类,这个要怎么实现
- 要将Int1定义为类变量属性,下面的定义对吗?为什么?如不对该怎么改?
- 用Java读取read卡的属性
- 高分求!如何创建一个UTF-8格式的文本文件!!!急急急!!!下午结贴,
- 一个关于applet的问题
- 如何在JFrame的menubar上增加一层panel
- 怎样输出程序运行时间?
- 怎么用swing在指定位置画矩形?
- JAVA APPLET 如何扑获用户在浏览器中按下文件菜单里的“关闭”和右上角的打叉按钮!!!!
- 在weblogic5.1中支持perl
- 我想调用图片的单击事件,再用函数动态加载图片,这样为什么不能实现???
- 谁用过installanywhere做JAVA的安装程序啊?为什么会出现中文问题阿
我的问题是怎样得到当前类所在的路径?
例如:
我在Public类A的一个函数中怎样得到A.class所在的路径?
类A的一个函数中调用
System.getProperty("user.dir");
不就是A的路径吗?
return this.getClass().getClassLoader().getSystemResource("A").getPath();
}
}
class A { String getPath() {
return this.getClass().getClassLoader().getSystemResource("A.class").getPath();
}
}
然后加上包名不就行了?!
getCanonicalPath()看看这个方法!
试了你的方法,返回值是null?
--- ZJQ
能给个例子吗?
1
package test;
class A {
String getPath() {
return this.getClass().getClassLoader().getSystemResource("test/A.class").getPath();
}
}2
package test;
class A {
String getPath() {
return this.getClass().getResource("A.class").getPath();
}
}哪种方法都可以,我都测试过了。
3x!!