BufferedWriter表现得很奇怪 [英] BufferedWriter is acting strange
问题描述
我正在尝试使用工作高分机制制作游戏,我正在使用java.io.BufferedWriter写入高分文件。我在高分上没有加密,我使用Slick2D和LWJGL进行渲染和用户输入。程序执行此代码:
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 highscore and I am using Slick2D and LWJGL for rendering and user input. The program executes this code:
FileWriter fstream = new FileWriter("res/gabjaphou.txt");
BufferedWriter writer = new BufferedWriter(fstream);
writer.write(score); // score is an int value
writer.close(); // gotta save m'resources! lol
我打开由此生成的文本文件,所有读取的内容都是问号。我不知道为什么会发生这种情况,我使用了我正在制作的另一个项目的其他代码,我对此没有任何问题......有谁知道为什么?这真烦人! :C
I open the text file generated by this and all it reads is a question mark. I don't know why this happens, and I used other code from another project I was making and I had no problem with that... Does anyone know why? This is really annoying! :C
推荐答案
BufferedWriter.write(int)用于编写单个字符,而不是整数。
BufferedWriter.write(int) is meant to write a single charecter, not a integer.
public void write(int c)
throws IOException
写一个字符。
覆盖:写在类Writer中
参数: c
- int
指定要写的字符
抛出: IOException
- 如果发生I / O错误
Overrides: write in class Writer
Parameters: c
- int
specifying a character to be written
Throws: IOException
- If an I/O error occurs
尝试
writer.write(String.valueOf(score));
这篇关于BufferedWriter表现得很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!