Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import java.util.*;
// 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 {
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