import java.io.BufferedReader; import java.io.FileReader; public class Count { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new FileReader("Data.txt")); int charCount =0; int wordCount=0; int lineCount=0; String line = null; while((line=br.readLine())!=null){ lineCount++; wordCount+=line.split(" ").length; charCount+=line.length()+1; } System.out.println("Character: "+charCount); System.out.println("Word: "+wordCount); System.out.println("Line: "+lineCount); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter