/ Published in: Java
1. Write a program that counts the number of characters including words and lines in a file. The program prompts the user for inputting the filename. Sample output as follows:
Please enter the filename: narrative.txt
File Sample.txt has
1732 characters,
204 words and 70 lines.
*** by c0deslayer ***
Please enter the filename: narrative.txt
File Sample.txt has
1732 characters,
204 words and 70 lines.
*** by c0deslayer ***
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
FileReader fReader; try { int lines = 0; int words = 0; int chars = 0; while((cursor = reader.readLine()) != null){ // count lines lines += 1; content += cursor; // count words { words++; } } chars = content.length(); // Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); //Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); }