URL的应用实例

作者在 2010-05-24 09:24:44 发布以下内容

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;
public class URLReader{
    public static void main(String args[]){
        try{
            URL tirc = new URL("http://www.google.cn/");
            BufferedReader in = new BufferedReader(new
                InputStreamReader(tirc.openStream()));
            String s;
            while((s = in.readLine())!=null)
                System.out.println(s);
            in.close();    
        }catch(MalformedURLException e) {
            System.out.println(e);    
        }catch(IOException e){
            System.out.println(e);
        }    
    }
}
 
import java.util.Scanner;
import java.net.URL;
import java.io.IOException;
import java.net.MalformedURLException;
public class URLReader{
    public static void main(String args[]){
        try{
            URL tirc = new URL("http://www.google.cn/");
            Scanner scan = new Scanner(tirc.openStream());
            while(scan.hasNext()){
                System.out.println(scan.next());
            }
        }catch(IOException e){
            System.out.println(e);
        }    
    }
}
网络编程 | 阅读 1277 次
文章评论,共1条
源本英明C
2010-06-21 16:16
1
<img src="image/face/5.gif" class="face">
游客请输入验证码
浏览275869次