【发布时间】:2018-03-12 10:25:10
【问题描述】:
我正在为我的程序将操作计数写入文件(表示为“OpCount”),但我不断收到一个奇怪的符号而不是整数。我尝试打印 OpCount 并且它输出了我正在寻找的数字,所以它只是 BufferedWriter 做了一些奇怪的事情。这是我的代码:
public void writeOpToFile() {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter("NumberOperations.txt"));
writer.write(OpCount);
writer.close();
} catch (IOException e) {
System.err.println("File was not found. Please make sure the file exists!");
}
}
【问题讨论】:
-
那是你的整数。使用
String.valueOf表示其字符串。 -
OptCount是什么类型? - 顺便说一句:请阅读并关注Java Naming Conventions
标签: java bufferedwriter operations