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:\Users\Administrator\Desktop\bg_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;

 

转载于:https://www.cnblogs.com/codeDevotee/p/11422453.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值