用正则表达式找出一个文件中有多少个邮箱地址

本人自己亲手写的,demo版,先备份一下。 

import java.io.*;

import java.util.regex.*;

public class FindEmail {
public static void main(String args[]) {
Pattern p = Pattern.compile("[\\w[.-]]+@[\\w[.-]]+\\.\\w+");
File f = new File("D:\\1.htm");
try {
StringBuffer sb = new StringBuffer();
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String s;
try {
s = br.readLine();
while(s!=null){
Matcher m = p.matcher(s);
while(m.find()){
System.out.println(m.group());
}
s = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}

posted @ 2010-01-27 20:27  zpdlut  阅读(494)  评论(0编辑  收藏  举报