Parsi Coders
source code Program for counting no. of Chars, Words and Lines in a file. - نسخه قابل چاپ

+- Parsi Coders (http://parsicoders.com)
+-- انجمن: Web Development and Design (http://parsicoders.com/forumdisplay.php?fid=47)
+--- انجمن: Java (http://parsicoders.com/forumdisplay.php?fid=93)
+--- موضوع: source code Program for counting no. of Chars, Words and Lines in a file. (/showthread.php?tid=6291)



source code Program for counting no. of Chars, Words and Lines in a file. - Amin_Mansouri - 11-28-2017

Program for counting no. of Chars, Words and Lines in a file.

سورس کد پیدا کردن تعداد کلمه ها و تعداد خط ها در یک فایل متنی

Source code
سورس کد :

کد:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication23;
import java.lang.*;
import java.io.*;
import java.util.*;
/**
*
* @author www.parsicoders.com
*/
public class JavaApplication23 {

   /**
    * @param args the command line arguments
    */


       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 : ");
               s=buf.readLine();
               buf=new BufferedReader(new FileReader(s));
               while((s=buf.readLine())!=null)
               {
                       line_count++;
                       st=new StringTokenizer(s," ,;:.");
                       while(st.hasMoreTokens())
                       {
                               word_count++;
                               s=st.nextToken();
                               char_count+=s.length();
                       }
               }
               System.out.println("Character Count : "+char_count);
               System.out.println("Word Count : "+word_count);
               System.out.println("Line Count : "+line_count);
               buf.close();
       }
}

            
   


Example : & Output :
کد:
run:
Enter filename : e:\33.txt
Character Count : 23
Word Count : 4
Line Count : 4
BUILD SUCCESSFUL (total time: 9 seconds)