我的缓冲作家正在我的 txt 文件中随机写入一些垃圾。我使用 int nodes = Integer.valueOf(NODES_TEXT_FIELD.getText());
来存储一个应该只接受整数的 TextField 的值。
这是我的作家:
private static void writeOnFile(BufferedWriter writer, int nodes){
try {
System.out.println(nodes);
System.out.println("Last check before write");
writer.write(nodes);
System.out.println(nodes);
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Failed to write data on file");
e.printStackTrace();
}
}
我的输出:
2
Last check before write
2
在我发现的文本文件中:'?(根据您输入的数字更改为另一个内存垃圾
有人知道可能出了什么问题吗?我在这里呆了5个小时直到现在..