缓冲写入器无法处理数组

Buffered Writer unable to process from array

我正在使用缓冲写入器从数组写入文件:

int[] scores = new int[5];
for (int i = 0; i < 5; i++) {
  scores[i] = 2; //Array of twos
}  

try {
  BufferedWriter output = new BufferedWriter(new FileWriter(new File("Scores.txt")));
    output.flush();
    for (int i = 0; i < 3; i++) {
      output.write(scores[i]);
      output.newLine();
    }
    output.close();
}
catch (IOException e) {
  //Do something
}

此代码最终会输入垃圾值,即边框的 ASCII 字符,即使整数数组具有有效数字也是如此。知道为什么会发生这种情况吗?

你能试试 output.write(Integer.toString(scores[i]));,这样你就可以写字符串而不是整数了吗?