This should count number of lines, words and characters into file.
But it doesn\'t work. From output it shows only 0
.
Code:
You could store every line in a List
and then linesCount = list.size()
.
Calculating charsCount
:
for(final String line : lines)
charsCount += line.length();
Calculating wordsCount
:
for(final String line : lines)
wordsCount += line.split(" +").length;
It would probably be a wise idea to combine these calculations together as opposed to doing them seperately.