import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class TestReg {

public static void main(String[] args) throws IOException {
StringBuffer buf = null;
String c=null;
File f = new File("E:/A","sb.html");

FileReader fr = new FileReader(f);
BufferedReader br =new BufferedReader(fr);
while((c=br.readLine())!=null){
buf.append(c);
}

Pattern  p =Pattern.compile("[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+");
Matcher m = p.matcher(buf);
if(m.find()){
System.out.println(m.group());
}

}
}

解决方案 »

  1.   

    楼主,你没有对buf实例化啊!
    StringBuffer buf= new StringBuffer();    //对于方法append的调用:先要对buf实例化
      

  2.   

    将StringBuffer buf = null;改成
    StringBuffer buf = new StringBuffer();
      

  3.   

    while((c=br.readLine())!=null){
    buf.append(c);

    报错问题解决了 ,可以这里我用了循环把所有的字符都加到buf的  为什么输出的的结果只是读到一行??
      

  4.   

    while((c=br.readLine())!=null){
    buf.append(c +"\r\n");
      

  5.   

    将StringBuffer buf = null;改成
    StringBuffer buf = new StringBuffer();
    将buf.append(c);改为
    buf.append(c +"\r\n");
    输出的的结果就是好几行了。。
      

  6.   

    报错问题解决了 ,可以这里我用了循环把所有的字符都加到buf的 为什么输出的的结果只是读到一行??while((c=br.readLine())!=null){
    buf.append(c +"\r\n");
    }
    while(m.find()){  拥有指针思想
    System.out.println(m.group());
    }