title: NumberFormatException when reading CSV file in java
body: <p>I'm beginner in java and kinda stuck in these two problems so I'm trying to 
  let the program read from a CSV file line by line.</p>
  
  <p>So in the file I have first row as String and the column is double.
  So the problem is when it read first line It's reading the titles as double and it gives me an error.</p>
  
  <p>By the way it is CSV file   </p>
  
  <p>The error i got are these below
  Exception in thread "main" java.lang.NumberFormatException: For input string: "CLOSE" This is first error    </p>
  
  <p>Second error >> at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecima‌​l.java:1222) –   </p>
  
  <p>Third error >> at java.lang.Double.parseDouble(Double.java:510)</p>
  
  <p>Forth error >>> at AlgorithmTrader.ReadInputData(AlgorithmTrader.java:63)  </p>
  
  <p>Fifth Error >>  at AlgorithmTrader.Run(AlgorithmTrader.java:16)</p>
  
  <p>Last error >> SimpleAlgorithmTradingPlatform.main(SimpleAlgorithmTradingPl‌​atform.java:15)    </p>
  
  <p>So the first row in the file has TIMESTAMP | Close | High | Low | open | volume and under each of those row there is numbers as double except volume has integer numbers </p>
  
  <p>Your suggestion will appreciated. Thanks</p>
  
  <pre><code>import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.ArrayList;
  import java.util.Scanner;
  
  public class AlgorithmTrader {
  
      public void Run() {
  
          ReadInputData();
      }
  
      public void ReadInputData() {
  
          // create object of scanner class for user input
          Scanner scan = new Scanner(System.in);
          // declare file name for input file
          String inputFileName = "";
  
          // input from user for input file
          System.out.print("Enter Input File Name: ");
          inputFileName = scan.nextLine();
          try {
              PrintWriter pw = new PrintWriter("output.csv");// to open the file
  
              // create a new file
              File file = new File(inputFileName);
              // create a new scanner object to read file
              Scanner readFile = new Scanner(file);
  
              // for each line data
              String line = "";
  
              line = readFile.nextLine();//skip the first line
  
              while (readFile.hasNextLine()) {
  
                  readFile.nextLine();
                  // pass file to scanner again
                  readFile = new Scanner(file);
  
                  ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
  
                  // read stock data line by line
  
                  while (readFile.hasNextLine()) {
                      // read line from file
                      line = readFile.nextLine();
                      // split line data into tokens
                      String result[] = line.split(",");
  
                      // variables to create a Stock object
  
                      String timestamp = result[0];
                      double close = Double.parseDouble(result[1]);
                      double high = Double.parseDouble(result[2]);
                      double low = Double.parseDouble(result[3]);
                      double open = Double.parseDouble(result[4]);
                      int volume = Integer.parseInt(result[5]);
  
                      // store data into ArrayList
                      list.add(readFile.next());
                      pw.print(list.add(readFile.next()));
  
                      Stock stock = new Stock(timestamp, close, high, low, open, volume);
                  }// end of while to read file
  
                  //close readFile object
                  readFile.close();
                  pw.close();//close file
              }
          } catch (FileNotFoundException e1) {
  
              System.out.println(" not found.\n");
              System.exit(0);
          } catch (IOException e2) {
              System.out.println("File can't be read\n");
          }
      }
  }
  </code></pre>
  
  <p>I have another file Stock class </p>
  
  <pre><code>public class Stock {
  
      String timestamp;
  
      double close;
      double high;
      double low;
      double open;
      int volume;
  
      Stock(String t, double c, double h, double l, double o, int v) {
          timestamp = t;
          close = c;
          high = h;
          low = l;
          open = o;
          volume = v;
      }
  
      public void settimestamp(String t) {
          this.timestamp = t;
      }
  
      public void setclose(double c) {
          this.close = c;
      }
  
      public void sethigh(double h) {
          this.high = h;
      }
  
      public void setopen(double o) {
          this.open = o;
      }
  
      public void setvolume(int v) {
          this.volume = v;
      }
  
      public String gettimestamp() {
          return timestamp;
      }
  
      public double close() {
          return close;
      }
  
      public double high() {
          return high;
      }
  
      public int volume() {
          return volume;
      }
  }
  </code></pre>
  
  <p>And The main method in another file as well</p>
  
  <pre><code>import java.text.DecimalFormat;
  
  public class SimpleAlgorithmTradingPlatform {
  
      public static void main(String[] args) {
  
          DecimalFormat fmt = new DecimalFormat("#0.00"); // to get the      DecimalFormat
  
          AlgorithmTrader test = new AlgorithmTrader();
  
          test.Run();
      }
  }
  </code></pre>