当我使用String split方法将字符串数组返回到先前维度的字符串数组时,返回的数组可能比之前标注的数组大,以存储检索到的字符串。似乎存储阵列动态地重新分配到维度 - 忽略最初固定的维度。实际上,此代码片段适用于存储大小为1个元素的位置,但在调用split方法后可以随后扩展为18个元素:
String[][] Parameter_table = new String[1][18];
String[] storage = new String[1];
try
{
//test
File rule = new File(filename);
Scanner scan = new Scanner(rule);
int i =0;
while(scan.hasNextLine())
{
String thisLine = scan.nextLine();
storage = thisLine.split("\t");
for(int k =0; k < storage.length;k++)
{
if(storage[k].isEmpty()){
storage[k]=null;
}
Parameter_table[i][k] = storage[k];
}
i++;
}
}