//最好是用自己的Tomcat服务器效果明显
import java.io.*;
import java.util.regex.*;
import java.net.*;
class GetMail
{
public static void main(String[] args) throws Exception
{
//getMail();
getNetMail();
}
//从网页中获取大量的弟子邮件
public static void getNetMail()throws Exception
{
URL url=new URL("http://192.168.2.71:8080/myweb/mail.html");
System.out.println("conn");
URLConnection conn=url.openConnection();
System.out.println(conn);
BufferedReader br=
new BufferedReader(new InputStreamReader(conn.getInputStream()));//获取从此打开的连接读取的输入流
String reg="\\w+@\\w+(\\.\\w+)+";
String line=null;
Pattern p=Pattern.compile(reg);//封装正则表达式对象
while ((line=br.readLine())!=null)
{
Matcher m=p.matcher(line);
while (m.find())
{
System.out.println(m.group());
}
}
}
public static void getMail()throws Exception
{
BufferedReader br=
new BufferedReader(new FileReader("mail.txt"));
String reg="\\w+@\\w+(\\.\\w+)+";
String line=null;
Pattern p=Pattern.compile(reg);//封装正则表达式对象
while ((line=br.readLine())!=null)
{
Matcher m=p.matcher(line);
while (m.find())
{
System.out.println(m.group());
}
}
}
}
|
|