关于用java.util.zip中的类来解压压缩包(*.zip)时的碰到的奇怪问题?

kkkkwx 2003-10-16 02:12:13
我用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)

...全文
302 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
meijing 2003-10-17
  • 打赏
  • 举报
回复
up
kkkkwx 2003-10-17
  • 打赏
  • 举报
回复
谢谢 chenqirui() !!!
压缩包是好的,问题就出在一碰到中文文件名时就出错了,如果没有中文文件名话,就不会出错

chenqirui 2003-10-16
  • 打赏
  • 举报
回复
你换一个zip文件,可能是压缩文件损毁了

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧