你的文件必须在classpath中,那才可以找到:public class GetPath{
...
public static void main(String[] arg){
String file = arg[0];
java.net.URL path =new GetPath().getClass().getResource(file);
}
...
public static void main(String[] arg){
String file = arg[0];
java.net.URL path =new GetPath().getClass().getResource(file);
}
p.list(System.out);
这可以找出你所有的计算机配置;
如果只是找出当前路径代码为
Properties p=System.getProperties( );
String userdir=p.get(”user.dir“)