请问如何获得自身程序所在的目录???

解决方案 »

  1.   

    http://blog.csdn.net/sunyujia/archive/2007/09/24/1798328.aspx使用new File(当前类.class.getClassLoader().getResource("").toURI()).getPath()
      

  2.   

    不行阿    使用 System.getProperties("user.dir"); ,怎么转成字符型???
    还有下面的语句出错:
        String str =   new file1(this.class.getClassLoader().getResource("").toURI()).getPath() ;
      

  3.   

    怎么会不行了
    是不是想得到一个文件位置字符串?
    String strFile = System.getProperties("user.dir")+"fileName.txt";
    "fileName.txt"是你要打开的文件
      

  4.   


    String strFile = System.getProperties("user.dir") 提示无法将 getProperties 转成 String 类型
      

  5.   

    System.out.println(System.getProperty("user.dir"));
      

  6.   

    为什么非得使用System.getProperty("user.dir");这个很不好用如果在tomcat下实际上是tomcat的bin目录  
    new File(当前类.class.getClassLoader().getResource("").toURI()).getPath()
    这个不行吗,利用当前类的类加载器取得绝对路径