Bre*_*ead 9 .net c# sharpziplib
我ICSharpCode.SharpZipLib.Zip.FastZip用来压缩文件,但我遇到了问题:
当我尝试压缩文件名中包含特殊字符的文件时,它不起作用.当文件名中没有特殊字符时,它可以工作.
我想你不能使用FastZip.您需要迭代文件并自己添加条目,指定:
entry.IsUnicodeText = true;
告诉SharpZipLib,条目是unicode.
string[] filenames = Directory.GetFiles(sTargetFolderPath);
// Zip up the files - From SharpZipLib Demo Code
using (ZipOutputStream s = new
ZipOutputStream(File.Create("MyZipFile.zip")))
{
s.SetLevel(9); // 0-9, 9 being the highest compression
byte[] buffer = new byte[4096];
foreach (string file in filenames)
{
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
entry.DateTime = DateTime.Now;
entry.IsUnicodeText = true;
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
s.Finish();
s.Close();
}
Run Code Online (Sandbox Code Playgroud)
FastZip如果您愿意,您可以继续使用,但您需要给它一个ZipEntryFactory创建ZipEntrys 的IsUnicodeText = true。
var zfe = new ZipEntryFactory { IsUnicodeText = true };
var fz = new FastZip { EntryFactory = zfe };
fz.CreateZip("out.zip", "C:\in", true, null);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4343 次 |
| 最近记录: |