Write a console program named WordCount
that reads a file and reports how many lines, words, and characters appear in it.
Suppose, for example, that the file lear.txt
contains the following passage from Shakespeare's King Lear:
Poor naked wretches, wheresoe'er you are,
That bide the pelting of this pitiless storm,
How shall your houseless heads and unfed sides,
Your loop'd and window'd raggedness, defend you
From seasons such as these? O, I have ta'en
Too little care of this!
Given this file, your program should be able to generate the following sample run (with user input shown like this):
File: lear.txt
Lines = 6
Words = 47
Chars = 248
For the purposes of this program, a word consists of a consecutive sequence of letters and/or digits, which you can test using the static method Character.isLetterOrDigit
.