EmailSpider

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class EmailSpider {

public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new FileReader("D:\\test.txt"));
String line =
"";
BufferedWriter bfw = new BufferedWriter(new FileWriter(
"D:\\t.txt"));
while((line=br.readLine()) != null) {
bfw.write(parse(line));
bfw.newLine();
}
bfw.flush();
bfw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

private static String parse(String line) {
Pattern p = Pattern.compile(
"[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+");
Matcher m = p.matcher(line);
StringBuffer buf = new StringBuffer();
while(m.find()) {
System.out.println(m.group());
buf.append(m.group());
}
return buf.toString();
}

}
lunzi   2007-11-28 13:41:17 评论:0   阅读:332   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog