好的,所以我正在实现一个系统,我保存在.txt文件中的计数.
计数是一个整数.
我唯一的问题是,而不是取代以前的计数; 例如
"78" -> "79"
Run Code Online (Sandbox Code Playgroud)
它将新计数添加到先前的计数; 例如
"78" -> "7879"
Run Code Online (Sandbox Code Playgroud)
我的代码是:
private static void saveCount(int inCount) throws FileNotFoundException, IOException {
BufferedReader fbr = new BufferedReader(new FileReader("count.txt"));
try (FileWriter fw = new FileWriter("count.txt", (fbr.readLine() != null))) {
String count = Integer.toString(inCount);
fw.write(count);
}
}
Run Code Online (Sandbox Code Playgroud)