System.IO.Compression.ZipFile .NET 4.5输出zip不适用于Linux/Mac/Java [英] System.IO.Compression.ZipFile .NET 4.5 output zip in not suitable for Linux/Mac/Java

查看:50
本文介绍了System.IO.Compression.ZipFile .NET 4.5输出zip不适用于Linux/Mac/Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用.NET System.IO.Compression.ZipFile.CreateFromDirectory 类时,在带有正斜杠目录分隔符的系统上严重提取了结果zip.

While using .NET System.IO.Compression.ZipFile.CreateFromDirectory class the outcome zip is badly extracted on system with forward-slash directory separator.

原因:邮政编码中的名称中包含反斜杠

Reason: The zip contains backslash inside the names

推荐答案

要解决此问题,存在一种解决方法:

To overcome this problem a workaround exists:

    class MyEncoder : UTF8Encoding
    {
        public MyEncoder()
        {

        }
        public override byte[] GetBytes(string s)
        {
            s = s.Replace("\\", "/");
            return base.GetBytes(s);
       }
    }
    System.IO.Compression.ZipFile.CreateFromDirectory("C:/ABC", "C:/tmp/ABC.zip", CompressionLevel.Fastest, false, new MyEncoder());

这篇关于System.IO.Compression.ZipFile .NET 4.5输出zip不适用于Linux/Mac/Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆