首页 > 学院 > 开发设计 > 正文

获取类加载的路径

2019-11-08 01:57:41
字体:
来源:转载
供稿:网友
// 第一种:获取类加载的根路径 //返回的路径:E:/Tomcat/apache-tomcat-6.0.35/webapps/xasj/WEB-INF/classes File f = new File(this.getClass().getResource("/").getPath()); System.out.PRintln(f);//第二种 获取当前文件所在的包目录/*E:/Tomcat/apache-tomcat-6.0.35/webapps/xasj/WEB-INF/classes/com/jeecms/cms/action/directive*/ File f2 = new File(this.getClass().getResource("").getPath()); System.out.println(f2); 1. 配置文件的加载 //获取 配置文件 jdbc.properties的jdbc.url字段的值String path = getClass().getClassLoader().getResource("/").getPath();+"../config/jdbc.properties";Properties p = new Properties();InputStream in = new FileInputStream(path);p.load(in);String url = p.getProperty("jdbc.url");
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表