在我的java程序中,我有一个日期文本文件,我试图将每个文件存储到一个数组中。然而,日,月和年继续存储到阵列的不同部分而不是一起请帮助我。这些是文本文件
中的一些行12/12 / 1996,23 / 08 / 2000,27 / 02/1980
12/04/1976,24/09 / 2003,13 / 06/1993
30/07/1995,20 / 06 / 2004,23 / 05/1990
private static String person1Date[];
private static String person2Date[];
private static String person3Date[];
static int count =0;
person1Date = new String[100];
person2Date = new String[100];
person3Date = new String[100];
File dateFiles = new File(dates.txt);
Scanner dates = new Scanner(dateFiles);
while(dates.hasNextLine)
{
String datesLine = dates.nextLine();
String [] datesDetails = datesLine.split(",");
person1Date[count] = datesDetails[0].trim();
person2Date[count] = datesDetails[1].trim();
person3Date[count] = datesDetails[2].trim();
count++;
}
答案 0 :(得分:0)
您尚未初始化用于设置要存储日期的数组位置的变量计数。写:
int count = 0;
在循环之前你已经完成了。