【发布时间】:2018-02-01 22:37:41
【问题描述】:
在保存游戏时,我想添加ints、Strings、booleans 等,因为这是我想要保存的游戏中的所有内容。唯一的问题是我能找到的只是how to add text to files? 那里没有任何帮助找到如何将数字和字母添加到非文本文件。
现在,这是我的代码:
private void saveGame() {
try {
//Whatever the file path is.
File statText = new File("F:/BLAISE RECOV/Java/Finished Games/BasketBall/BasketballGame_saves/Games");
FileOutputStream is = new FileOutputStream(statText);
} catch (IOException e) {
System.err.println("Problem writing to the file statsTest.txt");
}
}
【问题讨论】:
-
将所有这些字段组合到一个类中并使用Serialization..
-
您是要“将非文本添加到文件中”还是“将数字和字母添加到非文本文件中”,因为两者都在问题中?您可以尝试的一些事情是序列化或 JSON
-
我喜欢@AlexK。回复。保存对象比编写然后解析文本文件要容易得多。亚历克斯+1哦,帕尔萨的回答+1。没看到。