Pages

Ads 468x60px

Monday 17 December 2012

Check n.o of lines,words,characters in text file



13.      WAJP that displays the number of characters, lines and words in a text/text file.
Program:
                                    Download link to Filestatus
import java.io.*;

public class FileStat
{
  public static void main(String args[])throws IOException
  {
    long n1=0,nw=0,nc=0;
   
    String line;
   
    BufferedReader br=new BufferedReader(new FileReader(args[0]));
   
    while((line=br.readLine())!=null)
    {
      nl++;
     
      nc=nc+line.length();
     
      int i=0;
     
      boolean pspace=true;
     
      while(i<line.length())
      {
       char c=line.charAt(i++);
      
       boolean cspace=Character.isWhitespace(c);
      
       if(pspace&&!cspace)
        
         nw++;
        
       pspace=cspace;
      }
   }      
          

0 comments:

Post a Comment

 

Sample text

Sample Text

Sample Text