获取资源绝对路径的方法

使用当前web应用的根路径再拼接所需文件的路径可以得出文件的绝对路径
1     ServletContext context = this.getServletContext();
2     String realpath =context.getRealPath("所需文件路径");
使用类加载器获取.class文件的路径
1 Properties p = new Properties();
2             //获取字节码目录
3 String path=JdbcUtil.class.getClassLoader().getResource("db.properties").getPath();

 

posted @ 2020-03-01 11:35  CptMac  阅读(270)  评论(0)    收藏  举报
复制代码