title: Count/Frequency Distribution of Character Occurrences in File, Including Non-Visible
body: <p>My goal is to create a frequency distribution of every character in large flat files (1GB+) for later database import.  Ideally the output would be a list of ASCII characters each one followed by a count.</p>
  
  <p>I'm currently using a hashmap to create a distribution of every value in a string, and it kind of works, I'm just not sure how to implement this on a large file.   Additionally, in my output the CR and LF (or /r /n) characters result in a new line with the count on the next.</p>
  
  <p>Here is the current code:</p>
  
  <pre><code>public class CharCount{
  public static void main(String[] args) {
  
  String s = "abcdefghijklmnopqrstuvwxyz1234567890,.)(/\\&lt;&gt;?!@#$%^&amp;*_-+=\r\n";
  
  char[] arr = s.toCharArray();
  
  HashMap &lt;Character,Integer&gt; count = new HashMap&lt;Character, Integer&gt;();
  
  for (char c : arr) {
  
  try {
  count.put(c, count.get(c)+1);
  } catch (NullPointerException e) {
  
  count.put(c, 1);
  }
  }
  
  for (Character c: count.keySet()) {
  System.out.println(c + " = " + (int)c + " = " + count.get(c));
  }
  }
  }
  </code></pre>
  
  <p>The ideal output would look something like:</p>
  
  <blockquote>
    <p>000   NUL 4124435 
    001   SOH 0<br>
    002   STX 0<br>
    003   ETX 0<br>
    .....<br>
    253   ý   0<br>
    254   þ   0<br>
    255   ÿ   0  </p>
  </blockquote>
  
  <p>Definitely appreciate any help!</p>