- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 SharpZipLib 中的 FastZip 类创建一个 zip 文件,一旦关闭程序,我就无法删除该文件,因为:
“无法删除 zip.zip:它正在被其他人或程序使用。请关闭所有可能正在使用该文件的程序,然后重试。”
生成文件的代码如下:
fZip.CreateEmptyDirectories = true;
fZip.CreateZip(filesPath + "\\" + this.zipName, filesPath, false, this.zipFilter);
我尝试使用:
using (FastZip fZip = new FastZip())
{
try
{
fZip.CreateEmptyDirectories = true;
fZip.CreateZip(filesPath + "\\" + this.zipName, filesPath, false, this.zipFilter);
}
catch (Exception)
{
}
}
但它不会转换为 iDisposable
最佳答案
看起来这可能是 SharpZipLib 的一个错误。 FastZip.CreateZip 方法具有三个重载,其中两个重载使用 File.Create,例如:
CreateZip(File.Create(zipFileName), // ...
它似乎没有关闭流,所以你最好使用:
string zipFileName = System.IO.Path.Combine(filesPath, this.zipName);
using (Stream stream = File.Create(zipFileName))
{
fZip.CreateZip(stream, filesPath, false, this.zipFilter, null);
stream.Close();
}
从技术上讲,您不需要在 using block 中调用 Close,但我喜欢明确说明这一点。
关于c# - 无法删除由 SharpZipLib (FastZip) 创建的 Zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/340274/
不知道有没有办法用fastzip压缩一个目录,但只包括某些文件类型。我正在考虑使用类似的东西: public static void ZipFiles(string DirectoryToZi
我正在使用 ICSharpCode.SharpZipLib.Zip.FastZip 来压缩文件,但我遇到了一个问题: 当我尝试压缩文件名中包含特殊字符的文件时,它不起作用。它在文件名中没有特殊字符时有
我在使用 Mono 的 Mac 上使用以下代码来解压缩 zip 文件。 zip 文件包含目录下的条目(例如 foo/bar.txt)。但是,在解压后的目录中,FastZip 不是创建目录 foo 和文
我正在使用 SharpZipLib 中的 FastZip 类创建一个 zip 文件,一旦关闭程序,我就无法删除该文件,因为: “无法删除 zip.zip:它正在被其他人或程序使用。请关闭所有可能正在使
我是一名优秀的程序员,十分优秀!