Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.