@SuppressWarnings("rawtypes") public static void getProperties() { Properties properties = null; InputStream in = null; try { properties = new Properties(); //获取文件 in = Object.class.getResourceAsStream("/config.properties"); properties.load(in); Enumeration enumerations= properties.propertyNames(); //遍历输出 while(enumerations.hasMoreElements()){ String key=(String)enumerations.nextElement(); String value=properties.getProperty(key); System.out.println(key+"="+value); } } catch (IOException e) { e.printStackTrace(); //关闭InputStream } finally{ if(in != null){ try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } }
Java获取.properties文件,布布扣,bubuko.com
原文:http://blog.csdn.net/wintersweetsugar/article/details/36871459