zoukankan      html  css  js  c++  java
  • 通过URL获取页面内容

    1、

    public static void main(String[] args) {
    try {
    //创建一个URL实例
    URL url = new URL("https:/p.php");

    try {
    //通过URL的openStrean方法获取URL对象所表示的自愿字节输入流
    InputStream is = url.openStream();
    InputStreamReader isr = new InputStreamReader(is,"utf-8");

    //为字符输入流添加缓冲
    BufferedReader br = new BufferedReader(isr);
    String data = br.readLine();//读取数据

    while (data!=null){//循环读取数据
    System.out.println(data);//输出数据
    data = br.readLine();
    }
    br.close();
    isr.close();
    is.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    } catch (MalformedURLException e) {
    e.printStackTrace();
    }
    }

    }

    坚持就是胜利
  • 相关阅读:
    iOS开源控件库收集
    Ruby中的几种除法
    Font
    PlaySound
    STL
    APIs
    cin and cout
    CreateWindow
    Introducing Direct2D
    VC 常用代码
  • 原文地址:https://www.cnblogs.com/xiaotieblog/p/8311370.html
Copyright © 2011-2022 走看看