问题
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.
回答1:
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.
回答2:
The problem is really unknown. The problem happens for only that specified file. I've tried with other files and found no problems. Thank you guys.
来源:https://stackoverflow.com/questions/13788140/zip-and-unzip-files-using-dotnetzip