Zipinputstream
에서 Zipoutputstream
으로 Zip을 복사하려고합니다.Java : Zipinputstream에서 Zipoutputstream으로 "end-of-central-directory signature"로 연결됩니다. 오류
오라클 데이터베이스에 우편 번호 byte[]
을 저장합니다. 나는 Zipinputstream
을 사용하여 압축을 풀고 (나중에 Zip을 편집하고 싶습니다) Zipoutputstream
에 넣고 byte[]
을 새로 가져오고 나중에이 배열을 사용하여 ServletOutputStream
을 통해 파일을 다운로드합니다. Zipinputstream
이없는 새 파일을 만들면 작동합니다. 하지만 내가 Zipinputstream
을 사용할 때 오류가 발생합니다.
ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(fileFromDataBase),
Charset.forName("UTF-8"));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(byteArrayOutputStream, Charset.forName("UTF-8"));
ZipEntry currentEntry;
byte[] buffer = new byte[8192];
while ((currentEntry = zipInputStream.getNextEntry()) != null) {
ZipEntry newEntry = new ZipEntry(currentEntry.getName());
zos.putNextEntry(newEntry);
int length;
while ((length = zipInputStream.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
}
//TO Object to download later the Zipfile from html page
paketDownloadTO = new PaketDownloadTO();
paketDownloadTO.setData(byteArrayOutputStream.toByteArray());
paketDownloadTO.setFileName(fileName);
zos.finish();
zipInputStream.close();
zos.close();
왜? 그냥 바이트를 복사하십시오. 이 모든 합병증이 필요하지 않습니다. – EJP
나중에 zip을 편집해야합니다 (새 파일 넣기, 삭제 등). 그러나 일반 복사가 작동하지 않으면 편집 할 수 없습니다. – Sue