关于用java.util.zip中的类来解压压缩包(*.zip)时的碰到的奇怪问题?
我用zip包中的类来解压时,一碰到中文就出错,为什么,以下是我的原代码:
/**
* 根据要解压的文件,将压缩文件解压
* @param String s_zipname 要解压的文件名
* @param String s_pathname 要解压到的目录名
* @return boolean
*/
public boolean ExportZip(String s_zipname, String s_pathname) {
extPath=s_pathname;
zipname = s_zipname;
ZipInputStream zipis = null;
FileOutputStream fileoutputstream = null;
BufferedOutputStream bufferedoutputstream = null;
FileTools filetool = new FileTools();
String fullPath;
ZipEntry entry;
boolean result=false;
byte[] buffer = new byte[1024];
try {
zipis = new ZipInputStream(new FileInputStream(zipname));
while ((entry = zipis.getNextEntry()) != null) {
fullPath = extPath.replace("\\".charAt(0), "/".charAt(0)) +
entry.getName().replace("\\".charAt(0), "/".charAt(0));
filetool.CreatePath(fullPath);
File file = new File(fullPath);
if (!entry.isDirectory() && entry.getMethod()!=-1) {
fileoutputstream = new FileOutputStream(file);
bufferedoutputstream = new
BufferedOutputStream(fileoutputstream);
while ( (bytesread = zipis.read(buffer)) != -1)
bufferedoutputstream.write(buffer, 0, bytesread);
bufferedoutputstream.close();
fileoutputstream.close();
result=true;
}
}
zipis.close();
return result;
}
catch (IOException ex) {
System.out.println(ex);
return false;
}
finally {
try {
if (zipis != null) {
zipis.close();
}
if (bufferedoutputstream != null) {
bufferedoutputstream.close();
}
if (fileoutputstream != null) {
fileoutputstream.close();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
就这里:while ((entry = zipis.getNextEntry()) != null)
当它要获得条目时,就出错了,然后就抛异常
java.lang.IllegalArgumentException
at java.util.zip.ZipInputStream.getUTF8String(ZipInputStream.java:299)
at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:238)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:73)