- 论坛徽章:
- 0
|
java.util.Properties类的使用
这是我写的用于修改配置值的方法代码:
- static void updateConfigureValue(String targetFile, String parameterName, String parameterValue){
- Properties prop = new Properties();
- try {
- fis = new FileInputStream(targetFile);
- fos = new FileOutputStream(targetFile);
- prop.load(fis);
- prop.setProperty(parameterName, parameterValue);
- prop.store(fos, "Update '" + parameterName + "' value");
- }
- catch (IOException e) {
- System.out.println("Visit " + targetFile + " for updating " +parameterName + " value error");
- }
复制代码
问题是,由于fis和fos都指向了同一个文件,所以最后得到的property.txt成了这样的:
|
|