code: public static int getNumberOfColumnsInFile(String filename, String delimiter) {
      try {
        BufferedReader in = new BufferedReader(new FileReader(filename));
        String line;
        while ((line = in.readLine()) != null) {
          String[] parts = line.split(delimiter);
          in.close();
          return parts.length;
        }
        in.close();
        // File is empty.
        return 0;
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
docs: Counts the number of columns in a file delimited by {@code delimiter}.
  Assumes that the first line of the file is representative of the file as a
  whole.
  
  @param filename
  @param delimiter
  @return