Thursday, December 2, 2010

Read Text File Containing Email Addresses..

I wrote this small program to count email addresses in a text file. And to print email addresses one by one.

I use StringTokenizer class  to sort emails. You can use any character to sort out Strings.

For example, my file contains;; so I user ";" character to sort emails. You can use "@" character to collect user names of email addresses.

File Reader Class

import java.util.StringTokenizer;

public class FileReader {

    File file = new File("/root/Documents/emails.txt");
    StringBuffer contents = new StringBuffer();
    BufferedReader reader = null;
    String text = null;
    StringTokenizer st1;

    public void accessFile() {
             reader = new BufferedReader(new;
             while((text = reader.readLine()) != null){
                 st1 = new StringTokenizer(text, ";");
                 System.out.println("There are "+ st1.countTokens()+" email addresses!");

        }catch(FileNotFoundException e){
        }catch(IOException e){



Main Class

 * @author Isuru
public class EmailCounter {

    public static void main(String args[]){
        FileReader app = new FileReader();



No comments:

Post a Comment