zoukankan      html  css  js  c++  java
  • java中 文件压缩处理

    public static void main(String[] args) throws IOException {
            File file=new File("./mhxx_configs.xml");
            File zip=new File("./mhxx.zip");
            String name="configs.txt";                                    //压缩包里文件的名字
            InputStream iStream=new FileInputStream(file);
            FileOutputStream oStream=new FileOutputStream(zip);
            ZipOutputStream zStream=new ZipOutputStream(oStream);
            byte[] a=new byte[iStream.available()];
            zStream.putNextEntry(new ZipEntry(name));                         //一定要有  name为压缩包里文件名
            int read=0;
            while((read=iStream.read(a))>0) {
                zStream.write(a, 0, read);                                   //简单的文件压缩
            }
            
            ByteArrayOutputStream bStream=new ByteArrayOutputStream();       
            ZipOutputStream zStream2=new ZipOutputStream(bStream);
            zStream2.putNextEntry(new ZipEntry(name));
            zStream2.write(a);
            a=bStream.toByteArray();                                         //把文件压缩为byte[]    
            for(byte b:a) {
                System.out.print(b+" ");
            }
            
            
            zStream.closeEntry();                                           //流一定要记得关 不关  结果各种操蛋
            zStream.close();
            zStream2.close();
            iStream.close();
            oStream.close();
            bStream.close();
  • 相关阅读:
    关于《函数调用关键字》记忆恢复本
    进程一
    PE工具实现
    PE工具界面一
    PE各种操作
    汇编指令repne scas byte ptr es:[edi]
    Dialog
    按钮
    点和线的绘制一
    滚动条二
  • 原文地址:https://www.cnblogs.com/qiangqiangqiang/p/7743838.html
Copyright © 2011-2022 走看看