我有数据进入输入流。我有一个servlet,我可以获取数据。我想将收到的数据下载为文件。 这是我到目前为止提出的代码,但没有成功。任何帮助都会很棒!谢谢!
final InputStream inStream = new BufferedInputStream(fetchFile.getObjectContent());
byte[] bytes = IOUtils.toByteArray(inStream);
ServletOutputStream out = response.getOutputStream();
InputStream in = new ByteArrayInputStream(bytes);
response.setContentType("application/octet-stream");
response.setContentLength(bytes.length);
response.setHeader("Content-Disposition","attachment;filename=\"" + filename + "\"");
byte[] outputByte = new byte[bytes.length];
while(in.read(outputByte, 0, bytes.length) != -1)
{
out.write(outputByte, 0, bytes.length);
}
in.close();
out.flush();
out.close();