title: Reading from text file and storing contents in separate arrays
body: <p>I have a text file containing</p>
  
  <pre><code>r0, 0.5, 1
  r1, 0.6, -1
  r2, 0.2, 1
  </code></pre>
  
  <p>I want read the file and store each column in a separate array in java. This is the code I have been writing. I am only getting garbage values in the records. Also, I am not able read the float values. Please tell me how to fix this.</p>
  
  <pre><code>public class Model{
      private String modelname ;
  private String[] records ;
  private int[] targets ;
  private float[] scores ;
  
      public Model(String name_model, String path) throws NumberFormatException, IOException {
  
  
      this.modelname = path+name_model ;
      System.out.println(this.modelname);
  
      BufferedReader bufferReader = new BufferedReader(new FileReader(path+name_model));
      String line=null;
      int t=0;
      while((line = bufferReader.readLine())!=null) {
          System.out.println(line);
          //String[] strar = line.split(",");
          //String[] strar = line.split("\\s*,\\s*")  ;
          int k=1 ;
          for(String part : line.split(",")) {
              if (k==1) {
                  System.out.println(part.trim());
                  this.records[t] = part.trim() ;
                              }
              if (k==3)
                  this.targets[t] = Integer.valueOf(part.trim()) ;
              if (k==2)
                  this.scores[t] = Float.parseFloat(part.trim()) ;
              k=k+1 ;
          }
          System.out.println(this.records[t] + " " + this.targets[t] + " " + this.scores[t]);
          t=t+1;
      }
  }
  public static void main(String[] args) throws Exception, IOException {
  
      String s1, s2, s3 ;
      s1 = "./direc/" ;
      s2 = "file1.txt" ;
      s3 = s1+s2 ;
      System.out.println(s3);
      new Model(s2, s1);
  }
  </code></pre>
  
  <p>}</p>