`
linnaeus
  • 浏览: 17369 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

url实例

阅读更多
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;


public class URLTest {

//抽取股票信息字符串
public static void main(String[] args) {
  String result = null;
   try {  
        URL u = new URL("http://www.baidu.com");  
        byte[] b = new byte[256];  
        InputStream in = null;  
        ByteArrayOutputStream bo = new ByteArrayOutputStream();  
            try {  
                in = u.openStream();  
                int i;  
                while ((i = in.read(b)) != -1) {  
                    bo.write(b, 0, i);  
                }  
                result = bo.toString();
                bo.reset();  
            } catch (Exception e) {  
                System.out.println(e.getMessage());  
            } finally {  
                if (in != null) {  
                    in.close();  
                }  
            }  
    } catch (Exception ex) {  
        System.out.println(ex.getMessage());  
    } 
    System.out.println("result:" + result);
}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics