BufferedWriter is acting strange

后端 未结 3 1770
小蘑菇
小蘑菇 2021-01-16 14:02

I am trying to make a game with a working highscore mechanism and I am using java.io.BufferedWriter to write to a highscore file. I don\'t have an encryption on the highscor

3条回答
  •  囚心锁ツ
    2021-01-16 14:50

    Please use writer.write(String.valueOf(score)); otherwise it writes score as a character. See the documentation:

    Writes a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored.

    What you want to use is Writer.write(String); convert score to a String using String.valueOf or Integer.toString.

    writer.write(String.valueOf(score));
    

提交回复
热议问题