email extractor

email extractor

how to extract only email address from a lines of text file(.txt or .doc) and print in another file?
View Answers

January 1, 2010 at 9:10 AM

Hi,
Have a look at the below code and let me know if it helped you or if you have any further queries.

/**
* Program to scan email address from a file and write into an other file
*/
import java.io.*;
import java.util.regex.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
import java.util.StringTokenizer;

/**
* @author helper
*
*/
public class EmailExtractor {

ArrayList<String> emailsList = new ArrayList<String>();

public static void main(String[] args) {
EmailExtractor ex = new EmailExtractor();
ex.fileScanner();
}


public void fileScanner() {
String fileName = "emailAddress";
String line = null;
String email="";
try {
File file = new File(fileName);
FileReader fileReader = new FileReader(file);
BufferedReader reader = new BufferedReader(fileReader);
/*** Build a pattern of email address */
String regex ="^[\\w\\._-]+[@{1}]+[a-z+\\.{1,3}]+[a-z]$";
/***
* Explanation of RE: email address starts with alpha numeric characters,has '@'
* and has '.'at least once and to the max of three
* can also contain '_' '-'
* and ends with characters from a-z
* */
Pattern p = Pattern.compile(regex);
/*** Read each line of the line and break each line into tokens to see if it matches the pattern*/

while ((line = reader.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line);
while(st.hasMoreTokens()){
String token = st.nextToken();
Matcher m = p.matcher(token);
boolean result = m.matches();
/*** If a token matches the pattern, collect all the email address into an arrayList
* and use it later to write into an other file */
if(result){
email = m.group();
emailsList.add(email);
}
}
}
reader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
/*** write the email address to an other file. */
makeEmailList(emailsList);
}

public void makeEmailList(ArrayList emailArray){
String email="";
try{
FileWriter writer = new FileWriter("emailList.txt");
for(Iterator iter = emailArray.iterator(); iter.hasNext();){
email = (String) iter.next();
//System.out.println("email = "+email);
writer.write(email);
writer.write("\n");
}
writer.close();
}catch(IOException ex){
ex.printStackTrace();
}
}
}
------------------------------------------------------
a text file named: emailAddress.txt

Hi,

How are you doing?
I came to know you need help in writing a program.
I am woriking on it.
My email address is [email protected] or [email protected]
If any more queries, feel free to contact to my above email address.

Regards,
Helper.
-------------------------------------------------------
output in a file named emailList.txt

[email protected]
[email protected]









Related Tutorials/Questions & Answers:
ModuleNotFoundError: No module named 'email_extractor'
ModuleNotFoundError: No module named 'email_extractor'  Hi, My... named 'email_extractor' How to remove the ModuleNotFoundError: No module named 'email_extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'email_extractor'
ModuleNotFoundError: No module named 'email_extractor'  Hi, My... named 'email_extractor' How to remove the ModuleNotFoundError: No module named 'email_extractor' error? Thanks   Hi, In your python
Advertisements
email extractor - Java Beginners
email extractor  how to extract only email address from a lines... queries. /** * Program to scan email address from a file and write into an other..."; String line = null; String email=""; try { File file = new File
email extractor - Java Beginners
email extractor  how to extract only email address from a lines of text file(.txt or .doc) and print in another file? will u send me answer in c language? I have the idea ,copying one file text to another file by using buffer
email
email  how do i code for making clicking a send button sends a email
email
email   hi I am using 1and1 server. Using this server i am sending a mail using java program . But it is running some problem occur " Cannot send email. javax.mail.SendFailedException: Invalid Addresses;ADS_TO_REPLACE_1
E-Mail header extractor
E-Mail header extractor  i want to extract email header with using of java so please show the code of email extractor as result all the field show different color and or it extract ip where the email came
E-Mail header extractor
E-Mail header extractor  i want to extract email header with using of java so please show the code of email extractor as result all the field show different color and or it extract ip where the email came
ModuleNotFoundError: No module named 'Extractor'
ModuleNotFoundError: No module named 'Extractor'  Hi, My Python... 'Extractor' How to remove the ModuleNotFoundError: No module named 'Extractor' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'Extractor'
ModuleNotFoundError: No module named 'Extractor'  Hi, My Python... 'Extractor' How to remove the ModuleNotFoundError: No module named 'Extractor' error? Thanks   Hi, In your python environment you
email archiving
email archiving  Hi, What is email archiving? Thanks
Version of com.drewnoakes>metadata-extractor dependency
List of Version of com.drewnoakes>metadata-extractor dependency
Version of com.qwazr>qwazr-extractor dependency
List of Version of com.qwazr>qwazr-extractor dependency
ModuleNotFoundError: No module named 'bob.ip.caffe-extractor'
ModuleNotFoundError: No module named 'bob.ip.caffe-extractor'  Hi...: No module named 'bob.ip.caffe-extractor' How to remove the ModuleNotFoundError: No module named 'bob.ip.caffe-extractor' error? Thanks   Hi
ModuleNotFoundError: No module named 'bob.ip.tensorflow-extractor'
ModuleNotFoundError: No module named 'bob.ip.tensorflow-extractor'  ...: No module named 'bob.ip.tensorflow-extractor' How to remove the ModuleNotFoundError: No module named 'bob.ip.tensorflow-extractor' error? Thanks
ModuleNotFoundError: No module named 'date-extractor'
ModuleNotFoundError: No module named 'date-extractor'  Hi, My... named 'date-extractor' How to remove the ModuleNotFoundError: No module named 'date-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'description-extractor'
ModuleNotFoundError: No module named 'description-extractor'  Hi...: No module named 'description-extractor' How to remove the ModuleNotFoundError: No module named 'description-extractor' error? Thanks   Hi
ModuleNotFoundError: No module named 'epub-extractor'
ModuleNotFoundError: No module named 'epub-extractor'  Hi, My... named 'epub-extractor' How to remove the ModuleNotFoundError: No module named 'epub-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'freeotp-extractor'
ModuleNotFoundError: No module named 'freeotp-extractor'  Hi, My... named 'freeotp-extractor' How to remove the ModuleNotFoundError: No module named 'freeotp-extractor' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'har-extractor'
ModuleNotFoundError: No module named 'har-extractor'  Hi, My... 'har-extractor' How to remove the ModuleNotFoundError: No module named 'har-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'jsonschema-extractor'
ModuleNotFoundError: No module named 'jsonschema-extractor'  Hi...: No module named 'jsonschema-extractor' How to remove the ModuleNotFoundError: No module named 'jsonschema-extractor' error? Thanks   Hi
ModuleNotFoundError: No module named 'landmark-extractor'
ModuleNotFoundError: No module named 'landmark-extractor'  Hi, My... named 'landmark-extractor' How to remove the ModuleNotFoundError: No module named 'landmark-extractor' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'landmark-extractor'
ModuleNotFoundError: No module named 'landmark-extractor'  Hi, My... named 'landmark-extractor' How to remove the ModuleNotFoundError: No module named 'landmark-extractor' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'link-extractor'
ModuleNotFoundError: No module named 'link-extractor'  Hi, My... named 'link-extractor' How to remove the ModuleNotFoundError: No module named 'link-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'links_extractor'
ModuleNotFoundError: No module named 'links_extractor'  Hi, My... named 'links_extractor' How to remove the ModuleNotFoundError: No module named 'links_extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'location-extractor'
ModuleNotFoundError: No module named 'location-extractor'  Hi, My... named 'location-extractor' How to remove the ModuleNotFoundError: No module named 'location-extractor' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'lyrics-extractor'
ModuleNotFoundError: No module named 'lyrics-extractor'  Hi, My... named 'lyrics-extractor' How to remove the ModuleNotFoundError: No module named 'lyrics-extractor' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'metadata-extractor'
ModuleNotFoundError: No module named 'metadata-extractor'  Hi, My... named 'metadata-extractor' How to remove the ModuleNotFoundError: No module named 'metadata-extractor' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'news-extractor'
ModuleNotFoundError: No module named 'news-extractor'  Hi, My... named 'news-extractor' How to remove the ModuleNotFoundError: No module named 'news-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'numbers_extractor'
ModuleNotFoundError: No module named 'numbers_extractor'  Hi, My... named 'numbers_extractor' How to remove the ModuleNotFoundError: No module named 'numbers_extractor' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'organization-extractor'
ModuleNotFoundError: No module named 'organization-extractor'  Hi...: No module named 'organization-extractor' How to remove the ModuleNotFoundError: No module named 'organization-extractor' error? Thanks   Hi
ModuleNotFoundError: No module named 'pdf_extractor'
ModuleNotFoundError: No module named 'pdf_extractor'  Hi, My... 'pdf_extractor' How to remove the ModuleNotFoundError: No module named 'pdf_extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'person-extractor'
ModuleNotFoundError: No module named 'person-extractor'  Hi, My... named 'person-extractor' How to remove the ModuleNotFoundError: No module named 'person-extractor' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'safe-extractor'
ModuleNotFoundError: No module named 'safe-extractor'  Hi, My... named 'safe-extractor' How to remove the ModuleNotFoundError: No module named 'safe-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'scenecut-extractor'
ModuleNotFoundError: No module named 'scenecut-extractor'  Hi, My... named 'scenecut-extractor' How to remove the ModuleNotFoundError: No module named 'scenecut-extractor' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'sota-extractor'
ModuleNotFoundError: No module named 'sota-extractor'  Hi, My... named 'sota-extractor' How to remove the ModuleNotFoundError: No module named 'sota-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'statement-extractor'
ModuleNotFoundError: No module named 'statement-extractor'  Hi, My... named 'statement-extractor' How to remove the ModuleNotFoundError: No module named 'statement-extractor' error? Thanks   Hi
ModuleNotFoundError: No module named 'stock_extractor'
ModuleNotFoundError: No module named 'stock_extractor'  Hi, My... named 'stock_extractor' How to remove the ModuleNotFoundError: No module named 'stock_extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'stock_extractor'
ModuleNotFoundError: No module named 'stock_extractor'  Hi, My... named 'stock_extractor' How to remove the ModuleNotFoundError: No module named 'stock_extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'synonym-extractor'
ModuleNotFoundError: No module named 'synonym-extractor'  Hi, My... named 'synonym-extractor' How to remove the ModuleNotFoundError: No module named 'synonym-extractor' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'table-extractor'
ModuleNotFoundError: No module named 'table-extractor'  Hi, My... named 'table-extractor' How to remove the ModuleNotFoundError: No module named 'table-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'table-extractor'
ModuleNotFoundError: No module named 'table-extractor'  Hi, My... named 'table-extractor' How to remove the ModuleNotFoundError: No module named 'table-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'table-extractor'
ModuleNotFoundError: No module named 'table-extractor'  Hi, My... named 'table-extractor' How to remove the ModuleNotFoundError: No module named 'table-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'text-extractor'
ModuleNotFoundError: No module named 'text-extractor'  Hi, My... named 'text-extractor' How to remove the ModuleNotFoundError: No module named 'text-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'text-extractor'
ModuleNotFoundError: No module named 'text-extractor'  Hi, My... named 'text-extractor' How to remove the ModuleNotFoundError: No module named 'text-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'todo_extractor'
ModuleNotFoundError: No module named 'todo_extractor'  Hi, My... named 'todo_extractor' How to remove the ModuleNotFoundError: No module named 'todo_extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'todo_extractor'
ModuleNotFoundError: No module named 'todo_extractor'  Hi, My... named 'todo_extractor' How to remove the ModuleNotFoundError: No module named 'todo_extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'tree_extractor'
ModuleNotFoundError: No module named 'tree_extractor'  Hi, My... named 'tree_extractor' How to remove the ModuleNotFoundError: No module named 'tree_extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'ufo-extractor'
ModuleNotFoundError: No module named 'ufo-extractor'  Hi, My... 'ufo-extractor' How to remove the ModuleNotFoundError: No module named 'ufo-extractor' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'ufo-extractor'
ModuleNotFoundError: No module named 'ufo-extractor'  Hi, My... 'ufo-extractor' How to remove the ModuleNotFoundError: No module named 'ufo-extractor' error? Thanks   Hi, In your python

Ads