2 Replies - 1062 Views - Last Post: 12 April 2011 - 07:50 PM Rate Topic: -----

#1 sam1012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-May 09

Email Crawler in java, scan whole pc and search for any email address.

Posted 12 April 2011 - 03:21 AM

I want to make Email Crawler, i will give a path and my program will search for any email address found in files, i tried to find that is it a file or directive to start my logic. but it is not working...
please help me in this way....


package Email_Crawler;

import java.io.*;
import java.util.*;

public class Main {

   
    public static void main(String[] args) {

        File file = new File("C:\\abc");
        if(file.isDirectory()) 
          {
          String dir = file.getAbsolutePath(); // get path 
            directive(dir);  // call directive method
          }

        if(file.isFile())
        {
            String fil = file.getAbsolutePath();
            file(fil);
        }       
    }

   public static void directive(String dir)
    {
       String[] list = dir.split(dir); // dir.List() does not exist, how to get the list in directive
     for(int i = 0; i< dir.length() ; i++)
     {
         File f = new File(list[i]);
         if(f.isFile())
             System.out.print("File "+ i + " : " + f.getName() );
         else
             directive(list[i]);
     }

    }
   public static void file(String file)
    {

    }

}




Is This A Good Question/Topic? 0
  • +

Replies To: Email Crawler in java, scan whole pc and search for any email address.

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5313
  • View blog
  • Posts: 27,216
  • Joined: 10-May 07

Re: Email Crawler in java, scan whole pc and search for any email address.

Posted 12 April 2011 - 03:24 AM

What would be a practical use for this program? Sounds malicious.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Email Crawler in java, scan whole pc and search for any email address.

Posted 12 April 2011 - 07:50 PM

To crawl you need a recursive method that receives a directory as parameter
It extracts all the files from that directory when one of the file is a directory it calls back itself


  // start with a dir
  crawl(new File("\aDir");       // initial directory
  ....
}
private static void crawl(File dir) {
   // get list of files in the directory
   File[] list = dir.listFiles();
   // pass all the files in this directory
   for(int i = 0; i < list.length; i++) {
      // if the file is a directory call back myself
      if(file[i].isDirectory() {
         // call back myself to scan that directory
         crawl(file[i]);
      }
      else {
         // do your processing on regular file: file[i]
      }
    }  // enf for()
}


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1