房管局 网站做房查,phton可以做网站吗,免费建设个人手机网站,商城网站建设多少钱其实园子压缩解压缩的方法很多#xff0c;ZipOupputStream这个类的说明很多#xff0c;我这边也是从网上找的代码#xff0c;但是我在压缩的时候遇到了常见的两个问题#xff0c;第一个就是压缩的时候读取压缩包报该压缩包已经在另一个进程打开的bug#xff0c;这个问题解… 其实园子压缩解压缩的方法很多ZipOupputStream这个类的说明很多我这边也是从网上找的代码但是我在压缩的时候遇到了常见的两个问题第一个就是压缩的时候读取压缩包报该压缩包已经在另一个进程打开的bug这个问题解决方法是不能把创建的压缩包和被压缩的文件放在同一目录下因为当前目录已经被打开了。 第二个问题压缩文件夹无法把多个文件压缩遍历无法压缩多个文件原因是ZipOutputStream这个类库中的CRC32这个类本人表示查来查去也没找个那个大神的园子里解释过这个类总之把与这个类相关的代码注释掉就可以多个文件压缩了希望有懂得大神可以给解释下。 public class ZipFloClass { public void ZipFile(string strFile, string strZip) { if(File.Exists(strZip)) { File.Delete(strZip); } if (strFile[strFile.Length - 1] ! Path.DirectorySeparatorChar) strFile Path.DirectorySeparatorChar; FileStream fs new FileStream(strZip, FileMode.Create); ZipOutputStream s new ZipOutputStream(fs); s.SetLevel(6); // 0 - store only to 9 - means best compression zip(strFile, s, strFile); s.Finish(); s.Close(); } private void zip(string strFile, ZipOutputStream s, string staticFile) { if (strFile[strFile.Length - 1] ! Path.DirectorySeparatorChar) strFile Path.DirectorySeparatorChar; Crc32 crc new Crc32(); string[] filenames Directory.GetFileSystemEntries(strFile); foreach (string file in filenames) { if (Directory.Exists(file)) { zip(file, s, staticFile); } else // 否则直接压缩文件 { //打开压缩文件 FileStream fs File.OpenRead(file); byte[] buffer new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); string tempfile file.Substring(staticFile.LastIndexOf(\\) 1); ZipEntry entry new ZipEntry(tempfile); entry.DateTime DateTime.Now; entry.Size fs.Length; fs.Close(); //crc.Reset(); //crc.Update(buffer); //entry.Crc crc.Value; s.PutNextEntry(entry); s.Write(buffer, 0, buffer.Length); } } } }转载于:https://www.cnblogs.com/renzhitian/p/7903119.html