title: CSV reader picking up blank lines
body: <p>I have a program that reads in a <code>CSV</code> file and stores the first and last lines as a <code>JSONObject</code>. My current implementation is skipping over the last line and reading in a <code>null</code> value as the data object. </p>
  
  <p>What's the correct way to create/save a CSV file as to eliminate any white space or null values?</p>
  
  <p><strong>CSV</strong></p>
  
  <pre><code>   TIME_STAMP,TOTAL,APPLES,ORANGES,PEARS,GRAPES,TANGERINES,PINEAPPLES,CARROTS,UNKNOWN 
      7/1/2015 4:00,19474,1736,275,8366,5352,3003,393,349,
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre><code>String firstLine = "";
  String lastLine = "";
  
  int count = 0;
  if(reader != null){
      String aux = "";
      String lastLineMinusOne = "";
      while ((aux = reader.readLine()) != null) {
          if(count == 0)firstLine = aux;
              lastLineMinusOne = lastLine;
              lastLine = aux;
              count ++;
          }
          logger.info("Count = " + count);             
          String[] columns = firstLine.split(",");
          String[] data = lastLine.split(",");
          logger.info(firstLine);
          logger.info(lastLine);
  </code></pre>
  
  <p><strong>Log</strong></p>
  
  <pre><code>    2015-09-28 13:41:42,370 [ajp-0.0.0.0-8009-2] INFO  com.ChartData - Count = 3
      2015-09-28 13:23:27,745 [ajp-0.0.0.0-8009-3] INFO  com.ChartData - TIME_STAMP,TOTAL,APPLES,ORANGES,PEARS,GRAPES,TANGERINES,PINEAPPLES,CARROTS,UNKNOWN
      2015-09-28 13:23:27,745 [ajp-0.0.0.0-8009-3] INFO  com.ChartData -
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>java.lang.ArrayIndexOutOfBoundsException: 10
      at com.ChartData.getCSV(ChartData.java:75)
  </code></pre>
  
  <p>Line 75 -> <code>jObject.put("val", data[i]);</code></p>