zoukankan      html  css  js  c++  java
  • Java读取url

    public String read(String urlString){        
            try {
                StringBuffer html = new StringBuffer();  
                URL url = new URL(urlString);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                InputStreamReader inputReader = new InputStreamReader(conn.getInputStream());
                BufferedReader bufferedReader = new BufferedReader(inputReader);
                String temp;
                   while ((temp = bufferedReader.readLine()) != null) {
                    if(!temp.trim().equals("")){
                     html.append(temp).append("
    ");
                    }
                   }
                   bufferedReader.close();
                    inputReader.close();
                   return html.toString();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
  • 相关阅读:
    v-for基本使用
    SSH
    Git 命令
    bower笔记
    gulp使用例子
    yeoman使用例子
    grunt搭建
    不会误解的名字
    Python 多线程 多进程
    Python 协程
  • 原文地址:https://www.cnblogs.com/blog-wp/p/3304737.html
Copyright © 2011-2022 走看看