user.dir User's current working directory
String s = System.getProperty("user.dir");

解决方案 »

  1.   

    各位可能还没有理解我的意思?
    我的问题是怎样得到当前类所在的路径?
    例如:
    我在Public类A的一个函数中怎样得到A.class所在的路径?
      

  2.   

    受不了!!!!!!!!!!!!!!!!!!!
    类A的一个函数中调用
    System.getProperty("user.dir");
    不就是A的路径吗?
      

  3.   

    class A {  String getPath() {
        return this.getClass().getClassLoader().getSystemResource("A").getPath();
      }
    }
      

  4.   

    sorry,
    class A {  String getPath() {
        return this.getClass().getClassLoader().getSystemResource("A.class").getPath();
      }
    }
      

  5.   

    String s = System.getProperty("user.dir");
    然后加上包名不就行了?!
      

  6.   

    看看File类里面的方法吧!
    getCanonicalPath()看看这个方法!
      

  7.   

    to farawayzheng_necas(遥远):
    试了你的方法,返回值是null?
      

  8.   

    System.out.println(new File("").getAbsolutePath());
      

  9.   

    farawayzheng_necas(遥远) 的方法是对的ClassLoader.getSystemResource(String)要注意类有包名的情况。
    --- ZJQ
      

  10.   

    to zjq1980(阿易) :
    能给个例子吗?
      

  11.   

    比如说 A.class 是 test包下的

    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();
      }
    }哪种方法都可以,我都测试过了。
      

  12.   

    to farawayzheng_necas(遥远) 
    3x!!