我嘗試使用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