解压问题求解?
作者:海色珊瑚 2006-12-09 17:05:14
标签:
namespace Ehai.FileUnzip
{
public class Unzip
{
public void UnzipFiles(string SourceZip, string DesPath,bool cover)
{
ZipInputStream stream = new ZipInputStream(File.OpenRead(SourceZip));
ZipEntry theEntry;
if (!Directory.Exists(DesPath)) Directory.CreateDirectory(DesPath);
if (DesPath[DesPath.Length - 1] != Path.DirectorySeparatorChar
DesPath += Path.DirectorySeparatorChar;
while ((theEntry = stream.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
//生成解压目录
//Directory.CreateDirectory(directoryName);
if (directoryName != String.Empty)
{
if (Directory.Exists(DesPath + directoryName) && cover == false)
{
throw new Exception( "该文件已存在不能覆盖! "); return;
}
else
{
Directory.CreateDirectory(DesPath + directoryName);
cover = true;
}
}
if (fileName != String.Empty)
{
//解压文件到指定的目录
FileStream streamWriter = File.Create(DesPath + theEntry.Name);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = stream.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
stream.Close();
}
public void UnzipFiles(string SourceZip, string DesPath)
{
UnzipFiles(SourceZip, DesPath, false);
}
public void UnzipFiles(string SourceZip)
{
string DesPath = Path.GetDirectoryName(SourceZip);
UnzipFiles(SourceZip, DesPath, false);
}
}
}
这段代码我想直接用但不懂要调用什么头文件:
using System.IO.Compression;
//using System.IO.Compression.GZipStream;
using System.IO;
这样写这里都有错,ZipInputStream stream
该怎么写using 文件?
[解决办法]
ZipEntry、ZipInputStream是Java里的东东,C#里没有的.
VS2005,C#增加System.IO.Compression命名空间里的GZipStream,DeflateStream这两个类,提供压缩和解压
[解决办法]
不太清楚,帮你顶下