【发布时间】:2015-04-18 16:59:00
【问题描述】:
我是 StackOverflow 的新手,所以如果这个问题写得不正确,我很抱歉。
我目前正在学习 java,并且正在寻找一种将一组数组存储为文件的方法,以便对数组的更改将在程序的不同实例之间持续存在。我需要读取并将最佳时间列表的任何更改写入文件。
我对存储数组进行了一些研究,但我读过的大部分内容似乎只存储了一个简单的字符串、整数等数组。这些数组有点复杂,所以我不知道该怎么做。 我不希望任何人为我编写所有代码,但我可以使用一些帮助来了解从哪里开始。
这是需要存储的示例数据。这是 Java 游戏的最佳时机。
有没有办法将这类数据存储在某种文件中?
public class BestTimes
{
BestTimes[] beginner = new BestTimes[10];
BestTimes[] intermediate = new BestTimes[10];
BestTimes[] expert = new BestTimes[10];
public BestTimes() {
beginner[0] = new BestTimes(1, "John", 10.5);
beginner[1] = new BestTimes(2, "James", 20.3);
beginner[2] = new BestTimes(3, "Jill", 30);
beginner[3] = new BestTimes(4, "Bill", 35);
beginner[4] = new BestTimes(5, "Kevin", 40);
beginner[5] = new BestTimes(6, "Nate", 55);
beginner[6] = new BestTimes(7, "Bob", 75);
beginner[7] = new BestTimes(8, "Dan", 85);
beginner[8] = new BestTimes(9, "Amy", 93);
beginner[9] = new BestTimes(10, "Jane", 100);
intermediate[0] = new BestTimes(1, "John", 110.5);
intermediate[1] = new BestTimes(2, "James", 120.3);
intermediate[2] = new BestTimes(3, "Jill", 130);
intermediate[3] = new BestTimes(4, "Bill", 135);
intermediate[4] = new BestTimes(5, "Kevin", 140);
intermediate[5] = new BestTimes(6, "Nate", 155);
intermediate[6] = new BestTimes(7, "Bob", 175);
intermediate[7] = new BestTimes(8, "Dan", 185);
intermediate[8] = new BestTimes(9, "Amy", 193);
intermediate[9] = new BestTimes(10, "Jane", 200);
expert[0] = new BestTimes(1, "John", 210.5);
expert[1] = new BestTimes(2, "James", 220.3);
expert[2] = new BestTimes(3, "Jill", 230);
expert[3] = new BestTimes(4, "Bill", 235);
expert[4] = new BestTimes(5, "Kevin", 240);
expert[5] = new BestTimes(6, "Nate", 255);
expert[6] = new BestTimes(7, "Bob", 275);
expert[7] = new BestTimes(8, "Dan", 285);
expert[8] = new BestTimes(9, "Amy", 293);
expert[9] = new BestTimes(10, "Jane", 300);
}
public int ranking;
public String playerName;
public double time;
public BestTimes(int r, String p, double t)
{
ranking = r;
playerName = p;
time = t;
}
}
【问题讨论】:
-
我大部分时间都在阅读和研究如何做到这一点。我还没有写太多代码。我想出了如何将简单文本放入文件中,但这有很大不同。