我有一个使用BufferedReader.Readline()
从文本文件中读取的字符串,我想将其放入数组中。数组已满,并且一切正常,但是当我想访问数组的成员时,会引发IndexOutOfBoundsException
错误。
public static String[][] Rooms = new String[20][8];
public static String[] Roomstemp = new String[8];
BufferedReader br = new BufferedReader( new FileReader( new File( "RoomsData.txt" ) ) );
int i = 0;
String line="";
while((line=br.readLine())!=null)
{
Roomstemp = line.split( " " );
System.out.println( Arrays.deepToString( Roomstemp ) ); //this line works fine
System.out.println( Roomstemp[4] ); // this line throws eror
for (int j = 0; j <6 ; j++) {
Rooms[i][j]= Roomstemp[j]; //this line throws error too
}
i++;
}
为更准确地解释它,第一次编译while循环Roomstemp[4]
可以正常工作,但是在第二次编译循环时会抛出错误。