修改properties文件中的值,当达到9999时就从1重新开始循环。文件中的键值对如下:
#话单文件名 最后4位序列号 billFileNameNO:1 #话单文件头序列流水号 billHeaderStreamNO:1
public void modifyConfigField(String key,String value){
String path = BillService.class.getResource("/").getPath()+"BillContantNumber.properties";
Properties prop = new Properties();
InputStream fis = null;
OutputStream fos = null;
try {
File file = new File(path);
if (!file.exists())
file.createNewFile();
fis = new FileInputStream(file);
prop.load(fis);
fis.close();//一定要在修改值之前关闭fis
fos = new FileOutputStream(file);
int intValue;
String billFileNameNO = BillContantNumConfig.getValue(BillContantNumConfig.BillFileNameNO);
if("9999".equals(billFileNameNO)){
intValue = 1;
}else{
intValue = Integer.parseInt(value) +1;
}
String nextValue = String.valueOf(intValue);
prop.setProperty(key, nextValue); //设值-保存
prop.store(fos, "Update ‘" + key + "‘+ ‘"+nextValue);
} catch (IOException e) {
}
finally{
try {
fos.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
java修改properties文件中的键值对的值,布布扣,bubuko.com
原文:http://blog.csdn.net/liwf_/article/details/19935645