美文网首页
java中转下载第三方文件

java中转下载第三方文件

作者: IT男的假智慧 | 来源:发表于2021-12-02 17:34 被阅读0次

URL url =new URL("第三方文件URL");

HttpURLConnection conn =(HttpURLConnection) url.openConnection();

final ByteArrayOutputStream output =new ByteArrayOutputStream();

IOUtils.copy(conn.getInputStream(), output);

response.reset();

response.setHeader("Content-Disposition", "attachment; filename=" +(new String("测试名称.pdf".getBytes(), StandardCharsets.ISO_8859_1)));

response.setContentType("application/x-download");

byte[] buff =new byte[1024];

OutputStream os = response.getOutputStream();

BufferedInputStream bis =new BufferedInputStream(new ByteArrayInputStream(output.toByteArray()));

int i;

while ((i = bis.read(buff)) != -1) {

    os.write(buff, 0, i);

    os.flush();

}

bis.close();

os.close();

conn.disconnect();

相关文章

网友评论

      本文标题:java中转下载第三方文件

      本文链接:https://www.haomeiwen.com/subject/wzxuxrtx.html