Java中获得程序当前路径的4中方法

Java中获得程序当前路径的4中方法:
在Application中:

import java.util.*;

public class TestUserDir {

    public static void main(String[] args) {
        Properties property = System.getProperties();
        String str = property.getProperty("user.dir");
        System.out.println(str);

    }

}

或者:

import java.util.*;

public class getPath {
    public static void main(String[] args) {
        String s = System.getProperty("java.class.path");
        System.out.println(s);
    }
}

输出:F:/code/ec/JavaDBStudy

在Servlet中:

ServletContext servletContext = config.getServletContext();
String rootPath = servletContext.getRealPath("/");
posted @ 2013-11-28 14:27  cRaZy_TyKeIo  阅读(147)  评论(0编辑  收藏  举报