没办法,这是Java 的Bug……

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/1185/1185574.xml?temp=.9646112回复人: zhkn(小鱼儿) ( ) 信誉:100  2002-11-27 15:26:51  得分:100     今天也遇到这个问题,好不容易解决了,不过还是不爽,因为修改了相关类,而不能自己另写类。方法如下:1.将/jdk/jre/lib/rt.jar解包反编译ZipInputStream.class修改getUTF8String函数为:    private static String getUTF8String(byte b[], int off, int len)    {        String s = "";        try        {            s = new String(b, off, len, "GBK");        }        catch(Exception e)        {            System.out.println(e.toString());        }        return s;    }编译,打包。2.自己写的解包的类:import java.io.*; import java.util.*; import java.util.zip.*; import sun.io.*; public class UnZip {  public static void main(String filename)  {  System.out.println(filename); File infile = new File(filename);  try{  //检查是否是zip文件  ZipFile zip = new ZipFile(infile);  zip.close();  //建立与目标文件的输入连接  ZipInputStream in = new ZipInputStream(new FileInputStream(infile));  ZipEntry file = in.getNextEntry();  int i =infile.getAbsolutePath().lastIndexOf('.');  String dirname = new String();  if ( i != -1 )  dirname = infile.getAbsolutePath().substring(0,i);  else  dirname = infile.getAbsolutePath();  File newdir = new File(dirname);  newdir.mkdir();  byte[] c = new byte[1024];  int len;  int slen;  while (file != null){  i = file.getName().replace('/','\\').lastIndexOf('\\');  if ( i != -1 ){  File dirs = new File(dirname+File.separator+file.getName().replace('/','\\').substring(0,i));  dirs.mkdirs();  dirs = null;  }  System.out.print("extract "+file.getName().replace('/','\\')+" ........ ");  if (file.isDirectory()){  File dirs = new File(file.getName().replace('/','\\'));  dirs.mkdir();  dirs = null;  }  else{ FileOutputStream out = new FileOutputStream(dirname+File.separator+file.getName().replace('/','\\'));  while((slen = in.read(c,0,c.length)) != -1)  out.write(c,0,slen);  out.close();  }  System.out.print("o.k.\n");  file = in.getNextEntry();  }  in.close();  }catch(ZipException zipe){  System.out.println(infile.getName() + "不是一个zip文件!");  }catch(IOException ioe){  System.out.println("读取"+filename+"时错误!");  }catch(Exception i){  System.out.println("over");  }  } } 希望能解决你的问题,大家探讨一下更好的解决办法。
      

  2.   

    我说的是压缩过程,解压已经用上述方法搞定。
    试过了改变zipoutputstream里对应有一个getutf8bytes的方法,直接转换为gbk的字节数组,但写出来的文件名变成一堆???,估计是用gbk字节数组读入,最后还是按照utf-8的方式写出来。自然不对,是不是有可能来改变outputstream的encoding方式呢?
      

  3.   

    刚才全部搞定。压缩部分没有按照上面更改zipoutprintstream的思路来做。从其他论坛看见有高手自称解决压缩的问题。写了一份mail,然后得到了6个class,编入自己的包,全都解决了。不敢独享,有空间的朋友给我发mail,我把6个class代码寄给他,然后放在网上供大家共享。