This should count number of lines, words and characters into file.
But it doesn\'t work. From output it shows only 0
.
Code:
Looks like everyone is suggesting you an alternative,
The flaw with your logic is, you are not looping through the all the characters for the entire line. You are just looping through the first character of every line.
ch = in.next().charAt(0);
Also, what does 2 in charsCount -= linesCount * 2;
represent?
You might also want to include a try-catch block, while accessing a file.
try {
in = new Scanner(selectedFile);
} catch (FileNotFoundException e) {}