title: Splitting a CSV File in Java that has extra commas and extra quotes in them
body: <p>I need to parse a one-column CSV file that not only has extra commas but also some of the names include extra quotes.  I have looked over and have read the other previous questions and one of the best answers was <a href="https://stackoverflow.com/questions/15738918/splitting-a-csv-file-with-quotes-as-text-delimiter-using-string-split">Achintya Jha's Answer</a>.  However, that solution does not seem to work in my case.  An example is that the name</p>
  
  <pre><code>ADAMS COUNTY SHERIFF "ADAMS COUNTY SHERIFF'S OFFICE, CO"
  </code></pre>
  
  <p>is  being printed out as:</p>
  
  <pre><code>ADAMS COUNTY SHERIFF 
  "ADAMS COUNTY SHERIFF'S OFFICE, CO"
  </code></pre>
  
  <p>It is splitting at the correct spots and is taking care of the extra commas but not it is hitting the extra quotes and is splitting there now too, so <code>String csvSplitBy = ",(?=([^\"]*\"[^\"]*\")*[^\"]*$)";</code> will not work. Does anyone know of another way to handle this issue in Java? Other have asked this question for an answer in other languages but I could not find any, other then the one i linked to, about Java. Thanks!</p>
  
  <h2>This is my Java code:</h2>
  
  <pre><code>package csvdatacompareapplication;
  import java.io.*;
  
  public class CSVDataCompareApplication {
      public static void main(String[] args) {
  
          BufferedReader br = null;
          BufferedReader br2 = null;
          String customerListAllCustomers = "C:\\Users\\Desktop\\customerListAllCustomers.csv";
          String customerListToRemove = "C:\\Users\\Desktop\\customerListToRemove.csv";
          String line = "";
          String csvSplitBy = ",";
  
          try {
              br = new BufferedReader(new FileReader(customerListAllCustomers));
              while ((line = br.readLine()) != null) {
                  // use comma as separator
                  //String [] customersAll = line.split(csvSplitBy);
                  System.out.println(line);
              }
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } finally {
              if (br != null) {
                  try {
                      br.close();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }
      }
  
  }
  </code></pre>
  
  <h2>First few lines of my .CSV File</h2>
  
  <pre><code>ADAMS COUNTY SHERIFF'S OFFICE, CO
  ADAMSON POLICE PRODUCTS
  ADAN DAVILA
  ADAPT SECURE
  ADDISON PD - MIKE VINCENT
  ADDISON POLICE - IL
  ADDISON PORTER
  ADIN MCGARVIE
  ADMIRAL FIRE &amp; SAFETY
  ADMON IRAMIYA
  ADRIAN DANG
  ADRIAN HUMPHRIES
  ADRIAN KEPKA
  ADRIAN SALDANA
  ADRIAN SOLER
  ADRIAN YORK
  ADRIENNE BAKER
  ADRIENNE MOOS
  ADS INC.
  ADS, INC
  </code></pre>
  
  <p><strong>I updated my java code and now this is what prints out</strong></p>
  
  <pre><code>"ADAMS COUNTY SHERIFF'S OFFICE, CO"
  ADAMSON POLICE PRODUCTS
  ADAN DAVILA
  ADAPT SECURE
  ADDISON PD - MIKE VINCENT
  ADDISON POLICE - IL
  ADDISON PORTER
  ADIN MCGARVIE
  ADMIRAL FIRE &amp; SAFETY
  ADMON IRAMIYA
  ADRIAN DANG
  ADRIAN HUMPHRIES
  ADRIAN KEPKA
  ADRIAN SALDANA
  ADRIAN SOLER
  ADRIAN YORK
  ADRIENNE BAKER
  ADRIENNE MOOS
  ADS INC.
  "ADS, INC"
  </code></pre>
  
  <p><strong>Why did the quotes get placed in?</strong></p>