Java获取.properties文件

来源:互联网 发布:石家庄网站排名优化 编辑:程序博客网 时间:2024/04/19 17:46
@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();}}}}

0 0