zoukankan      html  css  js  c++  java
  • c# zip写comment注释

     //生成的压缩文件为test.zip
                using (FileStream fsOut = File.Create("test.zip"))
                {
                    //ZipOutputStream类的构造函数需要一个流,文件流、内存流都可以,压缩后的内容会写入到这个流中。
                    using (ZipOutputStream zipStream = new ZipOutputStream(fsOut))
                    {
                        //准备把G盘根目录下的vcredist_x86.exe文件添加到压缩包中。
                        string fileName = @"C:UsersAdministratorDesktopg_1.png";
                        FileInfo fi = new FileInfo(fileName);
                        //entryName就是压缩包中文件的名称。
                        string entryName = "bg_1.png";
                        //ZipEntry类代表了一个压缩包中的一个项,可以是一个文件,也可以是一个目录。
                        ZipEntry newEntry = new ZipEntry(entryName);
                        newEntry.DateTime = fi.LastWriteTime;
                        newEntry.Size = fi.Length;//把压缩项的信息添加到ZipOutputStream中。
                        zipStream.PutNextEntry(newEntry);
                        zipStream.SetComment("测试");
    
                        byte[] buffer = new byte[4096];
                        //把需要压缩文件以文件流的方式复制到ZipOutputStream中。
    
                        using (FileStream streamReader = File.OpenRead(fileName))
                        {
                            StreamUtils.Copy(streamReader, zipStream, buffer);
                        }
                        zipStream.CloseEntry();
                      
                        zipStream.IsStreamOwner = false;
                        zipStream.Finish();
                        zipStream.Close();
                    }
                }

    注意,这里有个坑。

    一开始以为是设置ZipEntry里面的Comment属性,看了下java 的demo,发现是设置outputstream的setComment

    dll下载地址:

    https://pan.baidu.com/s/1HcUabDjRlflalQoM0ZBo2Q

    读取comment值

    ZipFile zipFile = new ZipFile("C:\Users\Administrator\Desktop\2.zip");
    string str = zipFile.ZipFileComment;
  • 相关阅读:
    hadoop02---高可用网站架构
    springboot-vue项目前台2
    Java Serializable(序列化)
    JAVA 正则表达式、汉字正则、 java正则代码
    MyEclipse导入Maven项目
    JAVA学习:maven开发环境快速搭建
    删除
    关于java程序打包为EXE的若干问题
    ServletContext与ServletConfig的详解及区别
    在CSS中定义a:link、a:visited、a:hover、a:active顺序
  • 原文地址:https://www.cnblogs.com/codeDevotee/p/11422453.html
Copyright © 2011-2022 走看看