4-10 Filec

posted Apr 2, 2014, 10:48 AM by Dlovan ismail   [ updated Apr 2, 2014, 10:49 AM ]
/* 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);
    }
    
}

ċ
Filec.java
(1k)
Dlovan ismail,
Apr 2, 2014, 10:48 AM
Comments