System.getProperty("java.class.path");
或者
System.getProperty("user.dir");看哪一个符合你的要求。

解决方案 »

  1.   

    可不可以这样。File cur = new File(".");
    String path = cur.getPath();
      

  2.   

    楼上不可new java.io.File(".").getAbsolutePath()
    返回的String带"."
    System.getProperty("user.dir");
      

  3.   

    public class  TestPath
    {
    public static void main(String[] args) 
    {
                      String myPath=System.getProperty("java.class.path");
    System.out.println(myPath);
    }
    }
    输出效果如下:
    .;c:\j2sdk1.4.2\lib\;d:\ProgramJava;d:\ProgramJava\cannonBall;D:\ProgramJava\lesson7
      

  4.   

    public class  TestPath
    {
    public static void main(String[] args) 
    {
                      String myPath=System.getProperty("user.dir");
    System.out.println(myPath);
    }
    }
    输出效果如下:
    D:\ProgramJava\lesson7(我的源程序放在该目录下)
      

  5.   

    import java.io.*;
    public class  TestPath
    {
    public static void main(String[] args) 
    {
                      File cur = new File("path");
    String path = cur.getPath();
    System.out.println(path);
    }
    }
    经过测试发现
    输出结果就是创建File对象cur时给的参数“path”