如何解压带有Unicode文件名的zip文件?
以下是我的代码:
但我收到了错误:
try {
ZipInputStream zis = new ZipInputStream(
new FileInputStream(zipFile));
ZipEntry ze = zis.getNextEntry();
System.setProperty("file.encoding", "UTF-8");
while (ze != null) {
String fileName = new String(ze.getName().getBytes("UTF-8"));
System.out.println(fileName);
File newFile = new File(outputFolder + File.separator + fileName );
BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(newFile));
OutputStreamWriter osw = new OutputStreamWriter(outStream, Charset.forName("UTF-8"));
int ch;
StringBuffer buffer1 = new StringBuffer();
while ((ch = zis.read()) > -1) {
buffer1.append((char) ch);
}
osw.write(buffer1.toString());
osw.close();
outStream.close();
ze = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
} catch (IOException ex) {
ex.printStackTrace();
}
但我收到了错误:
UTFDataFormatException
:06-05 08:46:33.394: W/System.err(777): java.io.UTFDataFormatException: bad second or third byte at 6
06-05 08:46:33.394: W/System.err(777): at java.nio.charset.ModifiedUtf8.decode(ModifiedUtf8.java:56)
06-05 08:46:33.426: W/System.err(777): at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:270)
06-05 08:46:33.426: W/System.err(777): at com.learnlang.utility.ZipManager.unZipIt(ZipManager.java:62)
06-05 08:46:33.434: W/System.err(777): at com.learnlang.HomeActivity$progressThread.run(HomeActivity.java:317)
我的类名是ZipManager
。
如何解决这个问题?