Created
December 20, 2016 10:30
-
-
Save larsga/5e6abfbdc14ccde9e29d509e20f29d93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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