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();
            }
        }




  • 相关阅读:
    fiber
    ACM用到的算法。先做个笔记,记一下
    matlab安装及破解
    银行家算法
    网络安全(超级详细)零基础带你一步一步走进缓冲区溢出漏洞和shellcode编写!
    心脏滴血漏洞复现(CVE-2014-0160)
    KMP算法分析
    利用BURPSUITE检测CSRF漏洞
    BURPSUITE爆破密码
    动态规划—最长回文子串LEETCODE第5题深度剖析
  • 原文地址:https://www.cnblogs.com/TendToBigData/p/10501473.html
Copyright © 2011-2022 走看看