由于某种原因,以下代码在我的程序中被try-catch语句包围,但是它不能正常工作,因为它继续抛出NumberFormatException, 并擦除属性文件清除信息。感谢帮助。
File propFile = new File("path\to\file\properties.properties");
FileOutputStream outStream = new FileOutputStream(propFile);
FileInputStream inStream = new FileInputStream(propFile);
Properties prop = new Properties();
prop.load(inStream);
out.println(prop.getProperty("entryID"));
prop.setProperty("entryID", Integer.toString(Integer.parseInt(prop.getProperty("entryID"))+1));
prop.store(outStream, "");
答案 0 :(得分:0)
只需更改序列行,即可在阅读内容之前创建FileOutStream对象
请查找附件工作代码
文件propFile =新文件(“path \ to \ file \ properties.properties”);
FileInputStream inStream = new FileInputStream(propFile);
Properties prop = new Properties();
prop.load(inStream);
System.out.println(prop.getProperty("entryID"));
prop.setProperty("entryID", Integer.toString(Integer.parseInt(prop.getProperty("entryID"))+1));
FileOutputStream outStream = new FileOutputStream(propFile);
prop.store(outStream, "");