保存到配置文件

时间:2022-05-04
本文章向大家介绍保存到配置文件,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
/**
* 保存查询京东订单的开始时间与结束时间
*
* @param startDate
* @param endTime
* @return
* @throws IOException
*/
public void saveDate(String startDate, String endTime) {
Properties pro = new Properties();
String propertiesName = "jdStoreSearchDate.properties";
String TMP_DIR = this.getClass().getClassLoader().getResource("/").getPath();
String fileUrl = TMP_DIR + propertiesName;
//重新写入配置文件
FileOutputStream file = null;
try {
file = new FileOutputStream(fileUrl);
pro.put("startDate", startDate);//开始时间
pro.put("endTime", endTime);//开始时间
pro.store(file, "系统配置修改");
file.getFD().sync();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
file.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
System.out.println("保存开始时间和结束时间成功");
}