0
현재 다운로드 용 zip 파일을 만들어야합니다. 여기에는 문자열 변수에서 생성되는 두 개의 CSV 파일이 들어 있어야합니다. 나는 어떻게해야합니까? 내 초안은 아래와 같습니다.문자열 변수에서 text/csv가 포함 된 zip 파일 다운로드 생성
public @ResponseBody Object getFileV1(HttpServletRequest request, HttpServletResponse response) {
try {
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=Reassigned Tickets Report " + new Date().toString() + ".zip");
String stringValue1 = "This is a test value for csv1";
String stringValue2 = "This is a test value for csv2";
InputStream is1 = new ByteArrayInputStream(stringValue1.getBytes("UTF-8"));
InputStream is2 = new ByteArrayInputStream(stringValue2.getBytes("UTF-8"));
ZipInputStream zin;
ZipEntry entry;
ZipOutputStream zout= new ZipOutputStream(response.getOutputStream());
zin = new ZipInputStream(is1);
entry = zin.getNextEntry();
zout.putNextEntry(entry);
zin = new ZipInputStream(is2);
entry = zin.getNextEntry();
zout.putNextEntry(entry);
zout.closeEntry();
zin.close();
zout.close();
response.flushBuffer();
return null;
} catch (Exception e) {
e.printStackTrace();
return e;
}
}
분명히 작동하지 않습니다. 아마 내가이 초보자이기 때문일거야. 나와 함께 견뎌주세요.
"zout.putNextEntry"가 호출 된 줄에 "java.lang.NullPointerException"이 표시됩니다. 당신의 충고에 감사드립니다. 미리 감사드립니다.