我想读取一个文本文件并将内容添加到java中的二维数组中。但是当我将这些值添加到数组中时,我在 java 中得到了数组越界异常。
java.io.File test2 = new java.io.File("e:\\A.txt");
BufferedReader bw =new BufferedReader(new FileReader("e:\\A.txt"));
String s=bw.readLine();
while(bw.readLine()!=null)
{
counterRow++;
}
System.out.println(counterRow);
String sw=bw.readLine();
String[] words=s.split(",");
counterCol=words.length;
System.out.println(words.length);
@SuppressWarnings("resource")
Scanner input = new Scanner(test2);
String Data[][]=new String[counterRow][counterCol];
int i1=0,j1=0;
while(input.hasNext())
{
String val=input.nextLine();
j1=0;
if(val.contains(","))
{
String str[]=val.split(",");
int cn=str.length;
while(cn>0)
{
Data[i1][j1]=str[j1];
cn--;
j1++;
}
}
else
Data[i1][j1]=val;
i1++;
}
我的输入文件是
69,79,82
72,82,84
39,70,75
69,88,68
38,72,61
39,60,40
36,32,44
50,71,55
36,47,47
80,81,90
错误:com.associa.mining.AssociateRuleMiningAlgo.main(AssociateRuleMiningAlgo.java:200) 处的线程“main”100sssssss java.lang.NullPointerException 中的异常