title: Good and effective CSV/TSV Reader for Java
body: <p>I am trying to read big <code>CSV</code> and <code>TSV</code> (tab-separated) Files with about <code>1000000</code> rows or more. Now I tried to read a <code>TSV</code> containing <code>~2500000</code> lines with <a href="http://opencsv.sourceforge.net/" rel="noreferrer"><code>opencsv</code></a>, but it throws me an <code>java.lang.NullPointerException</code>. It works with smaller <code>TSV</code> Files with <code>~250000</code> lines. So I was wondering if there are any other <code>Libraries</code> that support the reading of huge <code>CSV</code> and <code>TSV</code> Files. Do you have any ideas?</p>
  
  <p>Everybody who is interested in my Code (I shorten it, so <code>Try-Catch</code> is obviously invalid):</p>
  
  <pre><code>InputStreamReader in = null;
  CSVReader reader = null;
  try {
      in = this.replaceBackSlashes();
      reader = new CSVReader(in, this.seperator, '\"', this.offset);
      ret = reader.readAll();
  } finally {
      try {
          reader.close();
      } 
  }
  </code></pre>
  
  <p>Edit: This is the Method where I construct the <code>InputStreamReader</code>:</p>
  
  <pre><code>private InputStreamReader replaceBackSlashes() throws Exception {
          FileInputStream fis = null;
          Scanner in = null;
          try {
              fis = new FileInputStream(this.csvFile);
              in = new Scanner(fis, this.encoding);
              ByteArrayOutputStream out = new ByteArrayOutputStream();
  
              while (in.hasNext()) {
                  String nextLine = in.nextLine().replace("\\", "/");
                  // nextLine = nextLine.replaceAll(" ", "");
                  nextLine = nextLine.replaceAll("'", "");
                  out.write(nextLine.getBytes());
                  out.write("\n".getBytes());
              }
  
              return new InputStreamReader(new ByteArrayInputStream(out.toByteArray()));
          } catch (Exception e) {
              in.close();
              fis.close();
              this.logger.error("Problem at replaceBackSlashes", e);
          }
          throw new Exception();
      }
  </code></pre>