public InputStream getFileStream(String strUrl) { InputStream inputStream = null; try { URL httpUrl = new URL(strUrl); HttpURLConnection httpURLConnection = (HttpURLConnection) httpUrl.openConnection(); httpURLConnection.setConnectTimeout(1000 * 3); httpURLConnection.setReadTimeout(1000 * 20); httpURLConnection.connect(); inputStream = httpURLConnection.getInputStream(); byte[] in = StreamUtils.copyToByteArray(inputStream); return new ByteArrayInputStream(in); } catch (Exception e) { LOGGER.error(e.getMessage(), e); throw new ApplicationException(10086, "获取文件内容失败,请重新上传"); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { LOGGER.error("inputStream.close", e); } } } }
根据文件地址获取输入流
最新推荐文章于 2024-03-26 00:31:52 发布