使用当前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();