c# 怎么解压缩rar的压缩文件?高手指点!
问题如题目,谢谢.
------解决方案--------------------rar是一个特定的软件,有着它的自己的格式,在C#里没有相应的一个类能和它完全一样的实现RAR的功能,
如果一定要处理,那么最好使用Process类来启动RAR的处理程序来专门的处理RAR文件.
------解决方案--------------------J#里面有个自解压的类库dll,可以在服务器端自解压的
忘了那个Dll的名字叫什么了
------解决方案--------------------还是应该用Process启动winrar
------解决方案--------------------调用这个就可以了.
public static void DecompressFile(string sourceFile, string destinationFile)
{
if (!File.Exists(sourceFile)) throw new FileNotFoundException();
using (FileStream sourceStream = new FileStream(sourceFile, FileMode.Open))
{
byte[] quartetBuffer = new byte[4];
int position = (int)sourceStream.Length - 4;
sourceStream.Position = position;
sourceStream.Read(quartetBuffer, 0, 4);
sourceStream.Position = 0;
int checkLength = BitConverter.ToInt32(quartetBuffer, 0);
byte[] buffer = new byte[checkLength + 100];
using (GZipStream decompressedStream = new GZipStream(sourceStream, CompressionMode.Decompress, true))
{
int total = 0;
for (int offset = 0; ; )
{
int bytesRead = decompressedStream.Read(buffer, offset, 100);
if (bytesRead == 0) break;
offset += bytesRead;
total += bytesRead;
}
using (FileStream destinationStream = new FileStream(destinationFile, FileMode.Create))
{
destinationStream.Write(buffer, 0, total);
destinationStream.Flush();
}
}
}
}
------解决方案--------------------到这里下载
http://www.rarlab.com/rar_add.htm