解压缩单个文件
代码如下 | 复制代码 |
using System.IO; // Create a compression stream pointing to the destiantion stream // Read the footer to determine the length of the destiantion file byte[] buffer = new byte[checkLength + 100]; int offset = 0; // Read the compressed data into the buffer if ( bytesRead == 0 ) offset += bytesRead; // Now write everything to the destination file // and flush everyhting to clean out the buffer if ( decompressedStream != null ) if ( destinationStream != null ) |
批量解压缩(这需要调用一个解压缩类库。。 ICSharpCode.SharpZipLib.dll)
代码如下 | 复制代码 |
using System; namespace ZipLib //如果解压目录存在 //是否为解压目录 //是否为解压文件 |
上面两个都是解压缩文件,下面我们把压缩与解压缩放在一个实例中。
最近要做一个项目涉及到C#中压缩与解压缩的问题的解决方法,大家分享。
这里主要解决文件夹包含文件夹的解压缩问题。
)下载SharpZipLib.dll,在http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx中有最新免费版本,“Assemblies for .NET 1.1, .NET 2.0, .NET CF 1.0, .NET CF 2.0: Download [297 KB] ”点击Download可以下载,解压后里边有好多文件夹,因为不同的版本,我用的FW2.0。
)引用SharpZipLib.dll,在项目中点击项目右键-->添加引用-->浏览,找到要添加的DLL-->确认
)改写了文件压缩和解压缩的两个类,新建两个类名字为ZipFloClass.cs,UnZipFloClass.cs
源码如下
代码如下 | 复制代码 |
using System; using System.IO; using ICSharpCode.SharpZipLib.Checksums; ///
if (Directory.Exists(file)) else // 否则直接压缩文件 byte[] buffer = new byte[fs.Length]; entry.DateTime = DateTime.Now; s.Write(buffer, 0, buffer.Length); }
、、、、、、、、、、、、、、、 using System; using ICSharpCode.SharpZipLib.BZip2;
public string unZipFile(string TargetFile, string fileDir) string rootDir = " "; if (dir == rootDir) //以下为解压缩zip文件的基本步骤 int size = 2048; streamWriter.Close(); return rootFile; |
)引用,新建一个页面,添加两个按钮,为按钮添加Click事件
源码如下
代码如下 | 复制代码 |
protected void Button1_Click(object sender, EventArgs e) } |
一切OK,可以测试一下,我是可以运行的。
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载荒野乱斗测试服 安卓版v61.10.3
下载荒野乱斗彩虹服 安卓版v61.10.3
下载寒霜启示录 安卓版v1.25.10
寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
末日城堡免广告版 安卓最新版v0.7.1
末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
甜蜜人生模拟器 最新版v1.4.5
甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
武器锻造师内置功能菜单 v10.4
武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
开放空间overfield 安卓版v1.0.5
开放空间Overfield是一款箱庭养成经营手游,让你在广阔