java中获得当前路径的方法

来源:互联网 发布:堀江由衣 知乎 编辑:程序博客网 时间:2024/05/16 07:37
 import java.io.File;

public class LocalPath {

    /**
     * 得到文件的当前路径
     * @param args
     */
    public static String GetCurrentPath()
    {
        return System.getProperty("user.dir",".");
    }
    public static void main(String[] args) {
          System.out.println(System.getProperty("user.dir","."));
          File   file   =   new   File(".");  
          String   s  =   file.getPath();
          System.out.println(s);
          System.out.println(file.getAbsolutePath());
          
    }

}
原创粉丝点击