工作快两年了,发现没什么积累的过程,开通技术博客也是必须得,随时供自己查录,也和大家一起分享技术。
下面是测试。[javaWeb工程读取.properties文件]
------------------------------------
1 /** 2 * 根据键读取值 3 * @return 4 */ 5 public static String readByKey(Object obj,String key){ 6 Properties props = new Properties(); 7 String basePath = obj.getClass().getClassLoader().getResource("/").getPath(); 8 File config = new File(basePath+"config.properties"); 9 InputStream in; 10 try { 11 in = new FileInputStream(config); 12 props.load(in); 13 String pValue = (String) props.get(key); 14 return pValue; 15 } catch (Exception e) { 16 return null; 17 } 18 }
浙公网安备 33010602011771号