2 weixin 39181207 weixin_39181207 于 2017.09.03 07:41 提问

UrlConnection和URL的getcontent的使用方法
 package com.newterm;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author Dam
 *未完成
 */
public class UrlConnectionDemo {
    public static void main(String[] args) throws Exception {
        URL baidu = new URL("http://www.sina.com/");
//      URLConnection bd = baidu.openConnection();
//      BufferedReader in = new BufferedReader(new InputStreamReader(bd.getInputStream()));
//      try {
//          Object content;
//      while((content=baidu.getContent())!=null)   
        BufferedReader in=new BufferedReader(new InputStreamReader(baidu.openStream()));
        try{
        Object content=baidu.getContent();
        System.out.println(content);
        } catch (Exception e) {
        System.out.println("internet error");
        }   


        in.close();

    }
}

结果出现
sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@3e3abc88

1个回答

caozhy
caozhy   Ds   Rxr 2017.09.03 09:13
Csdn user default icon
上传中...
上传图片
插入图片