| //获取文件中的邮箱 public static void main(String[] args) throws IOException {
 //定义规则\\w表示字母数字,\\W表示非字母数字
 String s="\\w+@\\w+(\\.\\w+)+";
 //读取文件
 BufferedReader br=new BufferedReader(new FileReader("d:\\a.txt"));
 String ss=null;
 while((ss=br.readLine())!=null){
 
 Pattern p=Pattern.compile(s);
 Matcher m=p.matcher(ss);
 //符合规则,输出
 while(m.find()){
 System.out.println(m.group());
 }
 }
 }
 |