- package day23;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class DatagramSocket1 {
- public static void main(String[] args)throws Exception{
- URL url=new URL("http:\\192.168.1.3:8080\\a.txt");//封装网页
- String reg="\\w+@\\w+(\\.\\w+)+";
- Pattern p=Pattern.compile(reg);//将正则表达式编译到模式中
- URLConnection conn=url.openConnection();
- BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String line=null;
- while((line=br.readLine())!=null){
- Matcher m=p.matcher(line);
- while(m.find()){
- System.out.println(m.group());
- }
- }
-
-
-
-
- }
- }
复制代码
|
|