JAVA学习之路

常用链接

统计

最新评论

JAVA 获得当前类的路径

转自:http://hi.baidu.com/applesky/blog/item/16cd6c2760a77e01908f9d3c.html
Java中获得程序当前路径的4中方法:

在Application中:



import java.util.*;

public class TestUserDir {



/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Properties property = System.getProperties();

String str = property.getProperty("user.dir");

System.out.println(str);

}



}

或者:
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 on 2008-05-08 10:21 joaquin25 阅读(2563) 评论(0)  编辑  收藏 所属分类: Java语言


只有注册用户登录后才能发表评论。


网站导航: