zip和解压缩文件使用DotNetZip [英] zip and unzip files using DotNetZip
问题描述
我使用DotNetZip。使用它来压缩mp3文件。
ZipFile zip = new ZipFile();
zip.Password =123;
zip.AddFile(R:\\abc\\a\\a 2 z.mp3);
zip.Save(R:\\abc\\a\\aaa.zip);
提取aaa.zip后,我得到了一个损坏的mp3文件。具有3.31MB的数据,当原来有3.62MB。如何解决这个问题?
任何帮助。
文档说明此处:
请注意,ZipFile类实现了IDisposable接口。
为了使ZipFile产生一个有效的zip文件,你可以使用
在using子句中(在VB中使用),或者显式调用Dispose()方法
。请参阅如何使用using子句的示例。
因此,尝试将您的代码包装在 / code> block:
using(ZipFile zip = new ZipFile())
{
zip.Password =123;
zip.AddFile(R:\\abc\\a\\a 2 z.mp3);
zip.Save(R:\\abc\\a\\aaa.zip);
}
另请参阅 保存
文档页面。 / p>
I am using DotNetZip. Using it to zip mp3 files.
ZipFile zip = new ZipFile();
zip.Password = "123";
zip.AddFile("R:\\abc\\a\\a 2 z.mp3");
zip.Save("R:\\abc\\a\\aaa.zip");
After extraction of aaa.zip, I get a corrupted mp3 file. Having 3.31MB data when original had 3.62MB. How to resolve this problem? Any help is appreciated.
The documentation states here:
Be aware that the ZipFile class implements the IDisposable interface. In order for ZipFile to produce a valid zip file, you use use it within a using clause (Using in VB), or call the Dispose() method explicitly. See the examples for how to employ a using clause.
So try to wrap your code in a using
block:
using (ZipFile zip = new ZipFile())
{
zip.Password = "123";
zip.AddFile("R:\\abc\\a\\a 2 z.mp3");
zip.Save("R:\\abc\\a\\aaa.zip");
}
Also refer to the various example on Save
documentation page.
这篇关于zip和解压缩文件使用DotNetZip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!