获取文件中邮件的示例

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

class  GetMails
{
	public static void main(String[] args) throws IOException
	{
		getMail();
	}

	public static void getMail()throws IOException
	{
		BufferedReader bufr = 
			new BufferedReader(new FileReader("mail.txt"));

		String line =null;

		String mailreg = "\\w+@\\w+(\\.\\w+)+";

		Pattern p = Pattern.compile(mailreg);

		while((line=bufr.readLine())!=null)
		{
			Matcher m = p.matcher(line);
			while(m.find())
			{
				System.out.println(m.group());
			}
		}
	}
}

 

你可能感兴趣的:(文件)