Java 从文件中读取整数值列后获取零

Java 从文件中读取整数值列后获取零,java,machine-learning,integer,bufferedreader,filereader,Java,Machine Learning,Integer,Bufferedreader,Filereader,所以我已经被这个问题困扰了一个星期了 我需要从我正在读取的文件的最后一列中获取值。 但是当我试图读取while循环之外的数组时,我得到的是零,而不是值 但是如果我在while循环中读取相同的数组,我就可以得到非常好的值 BufferedReader br2 = new BufferedReader(new FileReader("/home/manofsteel/yeast_training.txt")); // Starting to read a file line by

所以我已经被这个问题困扰了一个星期了

我需要从我正在读取的文件的最后一列中获取值。 但是当我试图读取while循环之外的数组时,我得到的是零,而不是值

但是如果我在while循环中读取相同的数组,我就可以得到非常好的值

    BufferedReader br2 = new BufferedReader(new FileReader("/home/manofsteel/yeast_training.txt"));
     // Starting to read a file line by line. 
      while((line = br2.readLine()) != null)
      {
        row = 0;
         String[] valsNew = line.trim().split("\\s+");  /* Getting rid of all
                                                         spaces since the file 
                                                         contains a lot of them. */

         cla = new int[lines];
         cla[row] = Integer.parseInt(valsNew[8]);  /* 8 because i need the
                                                 values from last column.  */


          row++;

      }
      for(int i=0;i<cla.length;i++)
        {
               // Trying to print back that array. 
                System.out.println("x"+cla[i]);
        }

}
我想要的输出是

  x4
  x1
  x1
  x1
  x2
  x7
  x2
  x7
欢迎提出任何建议

如果您认为我需要共享输入文件。一定要让我知道


谢谢

我认为这是行不通的,因为用于存储数据的数组总是在每次迭代中重新初始化:

cla = new int[lines];
而且,我也不确定每次执行新迭代时是否总是要将行设置为零(因为最后执行的是row++;):


您应该移动line
cla=newint[line]cla=newint[lines]
row=0
也在上面循环
cla = new int[lines];
row = 0;