Are you familiar with the wc
(word count) command? Here is what it does:
$ wc test.txt -l
33 //number of lines in test.txt
$ wc test.txt -w
165 //number of words in test.txt
$ wc test.txt -c
1730 //number of characters in test.txt
$ wc test.txt
33 165 1730 //lines, words, characters
Implement this subset of 'wc' in a java program.
Example usage of your program:
$ java -jar yourProgram.jar test.txt -l
33
$ java -jar yourProgram.jar test.txt -w
165
$ java -jar yourProgram.jar test.txt -c
1730
$ java -jar yourProgram.jar test.txt
33 165 1730
You are permitted to use Java 8 streams and lambdas.
Output the stats in JSON format:
java -jar yourProgram.jar test.txt
{
"lines":33,
"words":165,
"chars":1730
}
Hidden objective:
We will test your program only on ASCII files. Can you think of an optimization you can use here in one of the cases? :)