title: How can I quickly read a tab delimited file?
body: <p>I have a function to read in a tab delimited file which puts each column in a list and returns a list of lists with all the values from the column. This works fine for my small test file that I used with 1 column and 1850 rows, but I am now trying it with ~30k columns and it has been running for a few hours and still not finished. </p>
  
  <p>How can I modify the code below to do this faster? If reading in a file if 30k rows with 1850 columns is faster i can also transpose the input files.</p>
  
  <pre><code>public static List&lt;List&lt;String&gt;&gt; readTabDelimited(String filepath) {
      List&lt;List&lt;String&gt;&gt; allColumns = new ArrayList&lt;List&lt;String&gt;&gt;();
      try {
          BufferedReader buf = new BufferedReader(new FileReader(filepath));
          String lineJustFetched = null;
          for (;;) {
              lineJustFetched = buf.readLine();
              if (lineJustFetched == null) {
                  break;
              }
              lineJustFetched = lineJustFetched.replace("\n", "").replace("\r", "");
              for (int i = 0; i &lt; lineJustFetched.split("\t").length; i++) {
                  try {
                      allColumns.get(i).add(lineJustFetched.split("\t")[i]);
                  } catch (IndexOutOfBoundsException e) {
                      List&lt;String&gt; newColumn = new ArrayList&lt;String&gt;();
                      newColumn.add(lineJustFetched.split("\t")[i]);
                      allColumns.add(newColumn);
                  }
              }
          }
          buf.close();
      } catch (Exception e) {
          e.printStackTrace();
      }
      return allColumns;
  }
  </code></pre>