java从服务器下载大文件需要很长时间
我正在尝试从Kaltura下载文件(.mp4),文件超过100mb,下面的代码需要花很多时间下载
还有其他方法可以改进吗
try {
URL url = new URL("https://www.kaltura.com/p/....");
InputStream in = new BufferedInputStream(url.openStream());
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[8192];
int n = 0;
while (-1 != (n = in.read(buf)))
{
out.write(buf);
}
out.close();
in.close();
res.setContentType("application/octet-stream");
res.setHeader("Cache-Control", "no-cache");
res.setHeader("Content-Disposition","attachment;filename=Smac_03_48.mp4 (iPad).mp4");
res.setStatus(200);
res.getOutputStream().write(out.toByteArray());
} catch (Exception e) {
e.printStackTrace();
}
共 (0) 个答案