Skip to content

Instantly share code, notes, and snippets.

@larsga
Created December 20, 2016 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larsga/5e6abfbdc14ccde9e29d509e20f29d93 to your computer and use it in GitHub Desktop.
Save larsga/5e6abfbdc14ccde9e29d509e20f29d93 to your computer and use it in GitHub Desktop.
import java.util.*;
import java.io.FileReader;
import java.io.BufferedReader;
// read text file (plain text, no formatting)
// output how many times each word occurs in the text
// words consist only of A-Z/a-z, nothing else
// 'hello, Hello, jean-paul' => 'hello: 2 jean: 1 paul: 1'
public class Counter {
// usage: java Counter path/to/file.txt
public static void main(String[] argv) throws java.io.IOException {
BufferedReader reader = new BufferedReader(new FileReader(argv[0]));
String line = reader.readLine();
// line == null when file empty
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment