3
文字列で変換されたXMLのリストを圧縮しようとしていて、zipファイルに保存して、安静時のPOSTの本体として戻しています。しかし、ファイルを保存するたびに「アーカイブは不明な形式か破損しています」というエラーが表示されます。ZipOutPutStreamでファイルを圧縮するJava
protected ByteArrayOutputStream zip(Map<String, String> mapConvertedXml) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
try {
for(Map.Entry<String, String> current : mapConvertedXml.entrySet()){
ZipEntry entry = new ZipEntry(current.getKey() + ".xml");
entry.setSize(current.getValue().length());
zos.putNextEntry(entry);
zos.write(current.getValue().getBytes());
zos.flush();
}
zos.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return baos;
}
誰でも私を助けることができますか?
ネットワークに転送する前にzipファイルをチェックしてみましたか? – nandsito
使用している文字セットは何ですか? Stringの長さがバイト配列の長さと常に一致するわけではないためです。 – Boschi
@nandsitoいいえZipOutputStreamにはそのための関数がありますか? –