Write a java program to count the characters, words and lines from file.

Here we write a java program which count the number of  characters, words and lines of a given file.The java class name is WordCOunt.java and you have to create a file which should be in the same folder of java class. See the example in below mentioned class.

package com.javaforecast4u;
import java.lang.*;
import java.io.*;
import java.util.*;
class WordCount{
     public static void main(String arg[]) throws Exception
          int char_count=0;
          int word_count=0;
          int line_count=0;
          String s;
          StringTokenizer st;
          BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
          System.out.print("Enter filename : ");
          buf=new BufferedReader(new FileReader(s));
            st=new StringTokenizer(s," ,;:.");
         System.out.println("Character Count : "+char_count);
         System.out.println("Word Count : "+word_count);
         System.out.println("Line Count : "+line_count);

 Note: the file should be same folder in which java class is there.


  1. I agree with your thoughts!!! As the demand of java programming application keeps on increasing, there is massive demand for java professionals in software development industries. Thus, taking training will assist students to be skilled java developers in leading MNCs.
    Java Training in Chennai

  2. Thanks a lot for sharing this with all of us, I like it and we can communicate. Do you need buy app ratings and reviews. To boost app ranking and double app downloads now.

  3. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.

    sas training in bangalore

  4. Thanks a lot very much for the high your blog post quality and results-oriented help. I won’t think twice to endorse to anybody who wants and needs support about this area. https://www.besanttechnologies.com/training-courses/data-warehousing-training/big-data-hadoop-training-institute-in-bangalore

  5. Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
    java training in chennai
    java course in chennai

  6. This is really an awesome article. Thank you for sharing this.It is worth reading for everyone. Visit us:
    AWS Certification Training in Chennai | AWS Training Institute in Pallikaranai

  7. Good and more informative post... thanks for sharing your ideas and views... keep rocks and updating.........

    PCB Designing Training in Chennai | PCB Training Institute in Chennai | PCB Training in Velachery