读文件
Properties p1 = new Properties();
int accountTotal_last = 0;
try {
InputStream inputStream = new FileInputStream(this.getClass().getResource("/amount.properties").getPath());
p1.load(inputStream);
accountTotal_last =Integer.parseInt(p1.getProperty(yesterday));
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
写文件
InputStream inputStream;
Properties p2 = new Properties();
try {
inputStream = new FileInputStream(this.getClass().getResource("/amount.properties").getPath());
p2.load(inputStream);
OutputStream fos;
fos = new FileOutputStream(this.getClass().getResource("/amount.properties").getPath());
DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
p2.setProperty(today, String.valueOf(amountTotal));
p2.store(fos, df.format(new Date()));
inputStream.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}