Estou com um problema em um método, que aparentemente funciona 100%: le o arquivo ZIP, descompacta todos os arquivos no lugar certo, mantendo a hierarquia dos subdiretorios e arquivos, porem, os arquivos PNG descompactados, saem corrompídos ou algo do tipo. Eu tentei abrir manualmente os arquivos depois da descompactacao, e recebo uma mensagem
Dentro do arquivo zip, antes da descompactação, eu consigo visualizar a imagem numa boa
Alguem saberia me dar uma mao ?
Segue o codigo do metodo:
[code] public void descompacta(String path) throws FileNotFoundException, IOException {
final int BUFFER = 4096;
FileInputStream fis = new FileInputStream(path);
File zip = new File(path);
BufferedInputStream bis = new BufferedInputStream(fis, BUFFER);
ZipInputStream zis = new ZipInputStream(bis);
ZipEntry entrada = null;
String dir = zip.getCanonicalPath();
dir = dir.substring(0, dir.indexOf("."));
try {
if (!zip.isDirectory()) {
zip = new File(dir);
zip.mkdirs();
}
while ((entrada = zis.getNextEntry()) != null) {
int bytesLidos = 0;
byte[] dados = new byte[BUFFER];
StringBuffer strBuffer = new StringBuffer();
strBuffer.append(dir);
strBuffer.append(File.separatorChar);
strBuffer.append(entrada.getName());
String destino = String.valueOf(strBuffer);
File zipFile = new File(destino);
if (entrada.isDirectory()) {
zipFile.mkdirs();
continue;
}
if (!zipFile.getParentFile().exists()) {
zipFile.getParentFile().mkdirs();
}
FileOutputStream fos = new FileOutputStream(zipFile.getCanonicalPath());
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
while ((bytesLidos = zis.read(dados, 0, BUFFER)) != -1) {
dest.write(dados, 0, BUFFER);
}
dest.flush();
dest.close();
fos.close();
}
zis.close();
bis.close();
fis.close();
} catch (IOException iOException) {
System.out.printf("erro", iOException );
}
}[/code]