方法一、

//文件访问路径
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;
    }

  

 

相关文章:

  • 2022-01-06
  • 2021-08-11
  • 2021-07-27
  • 2022-12-23
  • 2021-09-12
  • 2021-09-16
  • 2021-12-16
  • 2021-12-03
猜你喜欢
  • 2021-08-16
  • 2021-06-20
  • 2022-12-23
  • 2021-09-07
  • 2021-09-27
  • 2021-09-30
  • 2022-12-23
相关资源
相似解决方案