zoukankan      html  css  js  c++  java
  • Java 读取网页简易程序

    package com.ibm.downloadtool;
    import java.io.BufferedInputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.Scanner;

    public class DownLoadTool {

        public static void main(String[] args) {
            // TODO Auto-generated method stub
            
            DownLoadTool d = new DownLoadTool();
            d.downLoadUrl("http://finance.sina.com.cn/");

        }
            //download
            public String downLoadUrl(String addr){
                StringBuffer sb=new StringBuffer();
                try {
                    URL url=new URL(addr);
                    HttpURLConnection con= (HttpURLConnection) url.openConnection();
                    con.setConnectTimeout(1000);
                    con.connect();
                    System.out.println(con.getResponseCode());
                    if(con.getResponseCode()==200){
                        BufferedInputStream bis=new BufferedInputStream(con.getInputStream());
                        Scanner sc=new Scanner(bis,"GBK");
                        while(sc.hasNextLine()){
                            sb.append(sc.nextLine());
                        }
                        sc.close();
                    }
                } catch (Exception e) {

                    e.printStackTrace();
                }
                System.out.println(sb.toString());
                return sb.toString();
            }
        }




  • 相关阅读:
    深入 聚集索引与非聚集索引(一)
    mysql 忘记root密码(linux ok, windows 没试)
    (转)关于中国的互联网
    log4j:启动tomcat发现 log4j:WARN No appenders could be found for logger 解决办法 转载
    log4j
    书签
    高级数据模型
    silverlight第三方控件
    实体框架资源
    RIASilverlight 程序开发框架3
  • 原文地址:https://www.cnblogs.com/TendToBigData/p/10501473.html
Copyright © 2011-2022 走看看