22) Write a java program that displays the number of characters, lines & words from a file.


import java.io.*;
class FilereadDemo
{
public static void main(String args[]) throws Exception
{
int ccnt=0,lcnt=1,wcnt=1,c;
FileInputStream fin=new FileInputStream(args[0]);
while((c=fin.read())!=-1)
{
ccnt++;
if(c==32 || c==13)
wcnt++;
if(c==13)
lcnt++;
}
System.out.println(“Number of Characters are ” + ccnt);
System.out.println(“Number of Words are ” + wcnt);
System.out.println(“Number of Lines are ” + lcnt);
}
}

Leave a comment