我尝试使用Zip4j生成zip文件进行下载。 但我总是得到错误:调用zout.putNextEntry(文件,NULL)时使用Zip4j生成Zip下载
2015-05-09 15:56:24.306 ERROR 11748 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: getOutputStream() has already been called for this response] with root cause
;下面
public void EmployeeEncyrptedZipFileDownload(HttpServletResponse response, @RequestParam(value = "id", required = true) int employeeId) throws IOException, ZipException
{
//Prepare text file contents
String fileContent = "Hallo Welt";
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment;filename=test.zip");
final StringBuilder sb = new StringBuilder(fileContent);
final ZipOutputStream zout = new ZipOutputStream(response.getOutputStream());
File file = new File("mytext.txt");
zout.putNextEntry(file, null);
byte[] data = sb.toString().getBytes();
zout.write(data, 0, data.length);
zout.closeEntry();
zout.finish();
}
函数如何是可能的,因为putNextEntry功能,即使没有得到回应,但媒体链接获得的流?
感谢,现在的作品, 但我有另一种方法,其中参数不为null,但: ZipParam eters parameters = new ZipParameters(); parameters.setEncryptFiles(true); parameters.setPassword(“AMOS”); 我已经添加了新参数: parameters.setSourceExternalStream(true); parameters.setFileNameInZip(“employee.txt”); 但它仍然无法正常工作,对此有何猜测? – Matombo