<pre name="code" class="java"> //读取
public RegisterPushInfoForm getRegisterPushInfo(){
String path =CouponsService.class.getResource("").getPath();
InputStream in = CouponsService.class.getResourceAsStream("../../../coupons.properties");//relative path local
Properties prop = new Properties();
RegisterPushInfoForm registerPushInfoForm=new RegisterPushInfoForm();
try {
prop.load(in);
String doPushStr = prop.getProperty("registerPush");
String idStr = prop.getProperty("couponsId");
idStr=idStr.replace("[","");
idStr=idStr.replace("]","");
boolean doPush = strToBoolean(doPushStr);
List<Integer> idList = strToList(idStr, ",", Integer.class);
registerPushInfoForm.setDoPush(doPush);
registerPushInfoForm.setCouponsIdList(idList);
in.close();
return registerPushInfoForm;
} catch (IOException e) {
e.printStackTrace();
logger.error("CouponsService.getRegisterPushInfo : load properties error");
return null;
}
}
//写入
public void updateRegisterPushInfo(RegisterPushInfoForm registerPushInfoForm){
Properties prop = new Properties();
try {
File file = new File(CouponsService.class.getResource("../../../coupons.properties").getFile());
OutputStream out = new FileOutputStream(file);
prop.setProperty("registerPush",String.valueOf(registerPushInfoForm.isDoPush()));
prop.setProperty("couponsId",registerPushInfoForm.getCouponsIdList().toString());
prop.store(out,"new register reward coupons");
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}