我的需求是从一堆文档中提取出qq邮箱,写了这篇帖子,希望能帮助和我有一样需求的人,谢谢!......
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class GetEmail {
public static void getEmail() {
File file = new File("E://itxm/email.txt");
try{
BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件
String s = null;
while((s = br.readLine())!=null){//使用readLine方法,一次读一行
Pattern pattern = Pattern.compile("[^0-9]");
Matcher matcher = pattern.matcher(s);
String email = matcher.replaceAll("");
if(!"".equals(email)&&email.length()>5){
System.out.println(email+"@qq.com");
}
}
br.close();
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
getEmail();
}
}