我的建议是查看Shared Preferences,您可以阅读Android 文档here。
如果您确实想使用单个字符串文件方法,我建议使用分隔符。这只是意味着在不同的整数值之间放置逗号或其他类型的分隔符。而不是"002007",将其另存为"002,007"。示例:
String s = "002,007"
String[] values = s.split(","); // values[0] is "002" and values[1] is "007"
使用.split(String) 命令将返回一个字符串数组,该数组中的每个元素都包含由参数分割的部分字符串,在本例中为:,
如果您想区分每个人的值,可以这样做:
String s = "002,007;003,008";
String[] people = s.split(";"); // people[0] is "002,007", people[1] is "003,004"
String[][] person = new String[people.length][people[0].split(",").length];
for (int i = 0; i < people.length; i++)
{
person[i] = people[i].split(",");
}
这是数组将包含的内容:
人[0][0]是“002”
人[0][1]是“007”
人[1][0]是“003”
人[1][ 1]是“008”
// print it for your own testing
for (String ppl[] : person)
{
for (String val : ppl)
{
System.out.print(val + " ");
}
System.out.println("");
}