当我打开文件以解压缩其内容时,出现以下异常。当我在 Windows 资源管理器中选择文件或将鼠标悬停在显示工具提示的文件上时,就会发生这种情况。
System.IO.IOException was unhandled
Message=The process cannot access the file 'D:\Documents\AutoUnZip\Zips\MVCContrib.Extras.release.zip' because it is being used by another process.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.OpenRead(String path)
at AutoUnzip.SelectFolderForm.w_Changed(Object sender, FileSystemEventArgs e) in D:\Projects\WindowsForms\AutoUnzip\AutoUnzip\SelectFolderForm.cs:line 37
at System.IO.FileSystemWatcher.OnCreated(FileSystemEventArgs e)
at System.IO.FileSystemWatcher.NotifyFileSystemEventArgs(Int32 action, String name)
at …Run Code Online (Sandbox Code Playgroud) 以及我将ICSharpCode.SharpZipLib.dll文件重命名为anythig的问题.我想缩短文件名.我在项目中引用程序集,但是当程序到达我使用库的语句时.它产生一个错误,它无法找到程序集或文件'ICSharpCode.SharpZipLib'.当我将文件名更改回ICSharpCode.SharpZipLib.dll时,应用程序正常工作.那么,有没有办法改变文件名.另外,我允许在不违反许可的情况下进行更改(我将在商业应用程序中使用它).谢谢.
我需要压缩一个字符串以减少 Web 服务响应的大小。我在 SharpZipLib 示例中看到了单元测试,但不是我所需要的示例。
在以下代码中,ZipOutputStream 的构造函数返回异常:“No open entry”
byte[] buffer = Encoding.UTF8.GetBytes(SomeLargeString);
Debug.WriteLine(string.Format("Original byes of string: {0}", buffer.Length));
MemoryStream ms = new MemoryStream();
using (ZipOutputStream zipStream = new ZipOutputStream(ms))
{
zipStream.Write(buffer, 0, buffer.Length);
Debug.WriteLine(string.Format("Compressed byes: {0}", ms.Length));
}
ms.Position = 0;
MemoryStream outStream = new MemoryStream();
byte[] compressed = new byte[ms.Length];
ms.Read(compressed, 0, compressed.Length);
byte[] gzBuffer = new byte[compressed.Length + 4];
System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);
System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);
string compressedString = Convert.ToBase64String (gzBuffer);
Run Code Online (Sandbox Code Playgroud)
我哪里跑偏了?我是否使这比应有的更复杂?
我有一个非常奇怪的问题.我使用SharpZipLib库生成.zip.我发现.zip的大小比我的文本文件总大一点.我不知道出了什么问题.我也尝试谷歌,但我找不到与我的情况有关的任何内容.这是我的代码:
protected void CompressFolder(string[] files, string outputPath)
{
using (ZipOutputStream s = new ZipOutputStream(File.Create(outputPath)))
{
s.SetLevel(0);
foreach (string path in files)
{
ZipEntry entry = new ZipEntry(Path.GetFileName(path));
entry.DateTime = DateTime.Now;
entry.Size = new FileInfo(path).Length;
s.PutNextEntry(entry);
byte[] buffer = new byte[4096];
int byteCount = 0;
using (FileStream input = File.OpenRead(path))
{
byteCount = input.Read(buffer, 0, buffer.Length);
while (byteCount > 0)
{
s.Write(buffer, 0, byteCount);
byteCount = input.Read(buffer, 0, buffer.Length);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个 zip 文件的字节 []。我需要在内存中解压缩文件并在 zip 中找到“dist”文件夹(总会有一个 dist 文件夹)并创建一个新的 zip 文件,其中包含“dist”文件夹中的任何内容。
“dist”文件夹中可以包含文件和子文件夹。我需要 byte[] 中的新 zip 文件,因此只能在内存中操作,无法访问物理磁盘。
我尝试使用“SharpZipLib”没有运气。我正在使用 .net 核心 2.0