Boa tarde, senhores!
Estou enfrentando um problema bem chato. Toda vez que zipo arquivos utilizando as facilidades do java.util.zip quando há arquivos do tipo texto eles são incluídos no arquivo zip, mas ficam com 0 (zero) bytes e totalmente vazios! Alguma luz?
Obrigado pela atenção!
Código:
private static void zipFiles(String strSource, File cpFile, ZipOutputStream cpZipOutputStream) {
if (cpFile.isDirectory()) {
File[] fList = cpFile.listFiles();
for (int i = 0; i < fList.length; i++) {
zipFiles(strSource, fList[i], cpZipOutputStream, textArea);
}
} else {
try {
CRC32 crc = new CRC32();
String strAbsPath = cpFile.getPath();
String strZipEntryName = strAbsPath.substring(strSource
.length() + 1, strAbsPath.length());
byte[] buffer = new byte[(int) (cpFile.length())];
ZipEntry cpZipEntry = new ZipEntry(strZipEntryName);
cpZipEntry.setSize(buffer.length);
crc.reset();
crc.update(buffer);
cpZipEntry.setCrc( crc.getValue());
cpZipOutputStream.putNextEntry(cpZipEntry);
cpZipOutputStream.write(buffer, 0, (int) cpFile.length());
cpZipOutputStream.closeEntry();
} catch (Exception e) {
e.printStackTrace();
}
}
}