读书人

properties的配备添加、删除、修改操作

发布时间: 2012-11-07 09:56:10 作者: rapoo

properties的配置添加、删除、修改操作

public void saveProperties(){try{Properties properties = new Properties();Properties p = new Properties();File file = new File("F://test.properties");p.load(new FileInputStream(file));Set<String> pSet = p.stringPropertyNames();Iterator i = pSet.iterator();while(i.hasNext()){String propertiesName = i.next().toString();//删除一个当获取的名称hk相同时,就返回到下一步;break;是退出循环if("hk".equalsIgnoreCase(propertiesName)) continue;properties.setProperty(propertiesName, p.getProperty(propertiesName));//修改if("japan".equalsIgnoreCase(propertiesName)){properties.setProperty(propertiesName, "123456789");}}properties.setProperty("usa", "美国");properties.setProperty("hk", "香港");properties.setProperty("japan", "日本");properties.setProperty("china", "中国");                                                //添加properties.store(new FileOutputStream(file), properties.toString());} catch (IOException e){e.printStackTrace();}}

?

读书人网 >编程

热点推荐