Java读取Properties文件[基础读取方式]
http://my.oschina.net/plumsoft/blog/66225
有一个properties文件box.properties,内容如下:
Color=RedName=BoxLength=18Width=7Heigth=8
InputStream in = null;Properties p = new Properties();try { in = new BufferedInputStream(new FileInputStream("box.properties")); p.load(in);} catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace();} catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();}Enumeration<Object> keys = p.keys();while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); System.out.println(key + ":" + p.getProperty(key));}
ResourceBundle rb = null;try { in = new BufferedInputStream(new FileInputStream("box.properties")); rb = new PropertyResourceBundle(in);} catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace();} catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();}if (rb != null) { Enumeration<String> keys = rb.getKeys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); System.out.println(key + ":" + rb.getString(key)); }}