URL에서 여러 파일을 읽을 수 있습니다 (즉, pdf, txt, tiff 등의 형식 일 수 있음). ZipOutputStream
을 사용하여 압축합니다. 내 코드는 다음과 같습니다메모리에서 파일 zip을
// using in-memory file read
// then zipping all these files in-memory
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
.....
URL url = new URL(downloadUrl); // can be multiple URLs
ByteArrayOutputStream bais = new ByteArrayOutputStream();
InputStream is = url.openStream();
byte[] byteChunk = new byte[4096];
int n;
while ((n = is.read(byteChunk)) > 0)
{
bais.write(byteChunk, 0, n);
}
byte[] fileBytes = bais.toByteArray();
ZipEntry entry = new ZipEntry(fileName);
entry.setSize(fileBytes.length);
zos.putNextEntry(entry);
zos.write(fileBytes);
zos.closeEntry();
// close the url input stream
is.close();
// close the zip output stream
zos.close();
// read the byte array from ByteArrayOutputStream
byte[] zipFileBytes = baos.toByteArray();
String fileContent = new String(zipFileBytes);
내가 다음 내 펄 프론트 엔드 응용 프로그램이 컨텐츠 "를 포함한 FileContent"을 통과하고있다.
그리고이 압축 파일 다운로드 펄 코드를 사용하고 있습니다 :
WPHTTPResponse::setHeader('Content-disposition', 'attachment; filename="test.zip"');
WPHTTPResponse::setHeader('Content-type', 'application/zip');
print $result; // string coming from java application
을하지만 지퍼가 손상되어주고있다 파일. 데이터 변환에 문제가 있다고 생각합니다.
어떤 도움을 주셔서 감사합니다.
Windows를 사용하는 경우는? – mob
번호. 리눅스를 사용. – Kevindra