title: Reading data from a csv file Java
body: <p>I want to read data from my dataset train.csv and I am trying to implement that using Java. My aim is to get this raw data in order to in the csv file in order to create a decision tree from this database. I have class DAO in which I implemented a method called extractTrainingData where I am writing the codes to read the data. This method is as follow. </p>
  
  <pre><code>public static BufferedReader exTractTraningData(File datafile, String ListOfCharacteristics) throws IOException {
  
      try {
          //create BufferedReader to read csv file
          BufferedReader reader = new BufferedReader(new FileReader(datafile));
  
          String strLine = "";
          StringTokenizer st = null;
  
          int lineNumber = 0, tokenNumber = 0;;
  
          String line = reader.readLine();
  
          while ((strLine = line) != null) {
              lineNumber++;
              //break comma separated line using ","
              st = new StringTokenizer(strLine, ",");
  
              while (st.hasMoreTokens()) {
                  //display csv values
                  tokenNumber++;
                  System.out.println("Line # " + lineNumber
                          + ", Token # " + tokenNumber
                          + ", Token : " + st.nextToken()
                           + ": " + line);
              }
              //reset token number
              tokenNumber = 0;;
          }
      } catch (Exception e) {
  
          System.out.println("Exception while reading csv file: " + e);
      }
      return null;
  }
  </code></pre>
  
  <p>When I run the main class, it repeats the row repeatedly. I don't really know if I am doing it correctly. I tried to follow an online tutorial. Can anyone help me out? Thank you</p>