发布时间:2020-05-07 17:12:52来源:本站阅读(1040)
先上代码
private void Zip(string strDir, ZipOutputStream s, string staticFile)
{
if (strDir[strDir.Length - 1] != Path.DirectorySeparatorChar) strDir += Path.DirectorySeparatorChar;
var crc = new Crc32();
var fileAndDir = Directory.GetFileSystemEntries(strDir);
foreach (var fad in fileAndDir)
{
if (Directory.Exists(fad))
{
Zip(fad, s, staticFile);
}
else
{
var fs = File.OpenRead(fad);
var buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
var tempFile = fad.Substring(staticFile.LastIndexOf("\\", StringComparison.Ordinal) + 1);
var entry = new ZipEntry(tempFile)
{
IsUnicodeText = true, DateTime = DateTime.Now, Size = fs.Length
};
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
}
}
}
这是修改后的。不乱码了。
开始的问题是遇到中文名字的文件夹或文件,放到压缩包就乱码了。百度到 https://blog.csdn.net/dongdongleng/article/details/7382763
IsUnicodeText = true
解决。
关键字: ICSharpCode
1057
1876
1622
1361
1470
822
1864
1610
1237
1825
9981
6165
5714
5285
4766
4466
3649
3516
3514
3423