zoukankan      html  css  js  c++  java
  • java 多个文件打包zip

    /**
     * 多个文件打包成zip
     */
    public class ZipDemo
    {
        private static void create() throws Exception{
            String path="d:/demo.zip";
            ZipOutputStream zipOut=new ZipOutputStream(new FileOutputStream(new File(path)));
            File[] files={new File("d:/1.doc"),new File("d:/2.doc")};
            byte [] buffer=new byte[1024];
            int len=-1;
            for(int i=0;i<files.length;i++){
                FileInputStream in=new FileInputStream(files[i]);
                zipOut.putNextEntry(new ZipEntry(files[i].getName()));
                while((len=in.read(buffer))!=-1){
                   zipOut.write(buffer, 0, len);
                }
                zipOut.closeEntry();
                in.close();
            }
            zipOut.close();
            System.out.println("文件已经压缩成zip了"+path);
        }
        public static void main(String[] args) throws Exception
        {
            create();
        }
    }
    

     

  • 相关阅读:
    7段数码管绘制
    画五角星
    绘制正方形
    蟒蛇的绘制
    玫瑰花
    小猪佩奇
    数列求和
    水仙花数
    鸡兔同笼
    画国际象棋盘
  • 原文地址:https://www.cnblogs.com/loveweiwei/p/4452636.html
Copyright © 2011-2022 走看看