Wednesday, May 25, 2022

java file program

 import java.io.*;

import java.util.*;

class search extends Thread{

   String file,args;

   String lino="";

   int count=0,flag=0;

   int linecount=0;

   search(String file,String args){

      this.file=file;

      this.args=args;

   }

   public void run(){

     try{

       File f=new File("/home/tejas/java_Text/6th sem/Thread/demo/"+file);

       Scanner sc=new Scanner(f);

       while(sc.hasNextLine()){

          String line = sc.nextLine();

          String words[]=line.split(" ");

          for(String word : words){

               if(word.equals(args)){

                  count++;

                  flag=1;

               }

          }

          if(flag==1){

             lino+=linecount+",";

             flag=0;

          }

          linecount++;

       }

       System.out.println("Thread name :"+this.getName()+"File name :"+file+"Line no :"+lino+"Count :"+linecount);

       }catch(Exception e){ System.out.println(e);}

   }

}

class main {

    public static void main(String[] args)throws Exception {

        

        File path=new File("/home/tejas/java_Text/6th sem/Thread/demo/");

        String files[] =path.list();

        search txt[] = new search[files.length];

        for(int i=0;i<files.length;i++){

           if(files[i].endsWith(".txt")){

                  txt[i]=new search(files[i],args[0]);

                  txt[i].start();

           }

        }   

    }

 }

No comments:

Post a Comment

How to make your own passport photos at home?

How to make your own passport photos at home?