zoukankan      html  css  js  c++  java
  • JAVA根据URL网址获取输入流

    
    

    方法一、

    //文件访问路径
    String url = "";
    InputStream intstream = new URL(url).openStream();

    方法二、

    public InputStream getInputStreamByUrl(String strUrl) {
            HttpURLConnection conn = null;
            try {
                URL url = new URL(strUrl);
                conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                conn.setConnectTimeout(20 * 1000);
                final ByteArrayOutputStream output = new ByteArrayOutputStream();
                IOUtils.copy(conn.getInputStream(), output);
                return new ByteArrayInputStream(output.toByteArray());
            } catch (Exception e) {
                logger.error("getInputStreamByUrl 异常,exception is {}", e);
            } finally {
                try {
                    if (conn != null) {
                        conn.disconnect();
                    }
                } catch (Exception e) {
                }
            }
            return null;
        }
    

      

     

  • 相关阅读:
    调用AsyncTask的excute方法不能立即执行程序的原因分析及改善方案
    辅助
    目录检索
    高斯消元法
    树套树
    珂朵莉树
    卢卡斯定理
    中国剩余定理
    数论基础
    网络流基础
  • 原文地址:https://www.cnblogs.com/jiehanshi/p/11528767.html
Copyright © 2011-2022 走看看