4-10 Filec
Post date: Apr 2, 2014 5:48:11 PM
/* read Text file and count Word and Line display entire text on the screen */
package filec;
import java.io.*;
import java.util.Scanner;
public class Filec
{
public static void main(String[] args)throws IOException
{
Scanner scan=new Scanner(System.in);
System.out.print("Enter Your File Path : ");
File f=new File(scan.next());
Scanner input=new Scanner(f);
int lines=0,word=0;
System.out.println("Display entire text on the screen :");
while(input.hasNextLine())
{
lines++;
String sline=input.nextLine();
System.out.println(sline);
Scanner wline=new Scanner(sline);
while(wline.hasNext())
{
word++;
wline.next();
}
}
input.close();
System.out.printf("Numner Of Lines=%s\n",lines);
System.out.printf("Numner Of Word=%s\n",word);
}
}