在web-inf下的属性文件,如何读取?? 如果是这样那路径不多,你可以这样,你首先用getClass().getResource("这里是你本文件的类名"); 这样取得了你所在应用的classes 目录,然后你该知道怎么做了吧,通过处理可以得到你想要的路径 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可是我的java类是放在jar包里的,而属性文件不能放在jar包里,因为该属性文件是可以修改的。 因为web-inf目录不是web项目的类路径,所以不能使用加载资源的方式读取,把这个类拷贝到web-inf\classes目录下就可以getClass().getResource("/test.properties");来读取http://www.javayou.com 将properties文件放到web-inf/classes目录下,如果没有这个目录新建一个就可以了 ./test.properties; 就OK了 Properties property= new Properties(); try{ FileInputStream in = new FileInputStream(servletContext.getRealPath( "WEB-INF/test.properties")); property.load(in); }catch (java.io.FileNotFoundException ex){ ex.printStackTrace(); }catch (java.io.IOException ioe){ ioe.printStackTrace(); } Properties props = new Properties(); String fileName = "aa.properties"; FileInputStream in = new FileInputStream(fileName); props.load(in); 主键定义成varchar(2) 高分求助hibernate一直困惑的问题,求解释!!! 一个多条件查询的问题? spring定时器引起系统变慢 求socket 客户端程序,接收ASCII数据流 hibernate映射问题 struts问题 struts2.0.14中没有<s:tree>标签吗? 在jsp中如何用代码将将“IE工具-=>ie 选项-=>高级-=>最下面的"总是以utf-8方式发送url"”项取消 谈一谈对HIBERNATE的看法 讨论jstl和struts的标记库! 在weblogic中读取applocation.properties出现问题?急。。。
try{
FileInputStream in = new FileInputStream(servletContext.getRealPath(
"WEB-INF/test.properties"));
property.load(in);
}catch (java.io.FileNotFoundException ex){
ex.printStackTrace();
}catch (java.io.IOException ioe){
ioe.printStackTrace();
}
String fileName = "aa.properties";
FileInputStream in = new FileInputStream(fileName);
props.load(in);