本人对此比较陌生.
麻烦指导一下对byte[]的数据怎么进行用java.util.zip的类进行压缩,而不用转换为文件.
以及如何将得到的数据再转换为正常的byte[].
谢谢各位指点!希望能有详细的代码指导,而不是告诉我怎么样怎么样.
多谢!

解决方案 »

  1.   

    以下就是从fileIn 中读取字节流,再压缩的。
    private static void zipAFile(File f, ZipOutputStream out, String base) throws Exception {
            FileInputStream fileIn = new FileInputStream(f);
            String entryName = f.getPath().substring(base==null?0:base.length()+1);
            ZipEntry entry = new ZipEntry(entryName);
            entry.setTime(f.lastModified());
            out.putNextEntry(entry);
            int b = 0;
            byte[] buffer = new byte[1024];
            while ((b=fileIn.read(buffer)) != -1){
                out.write(buffer,0,b);
            }
            out.closeEntry();
            fileIn.close();
        }