//压缩文件
public static void ZGip(string fileName, string gipFileName)
{FileStream fc = File.OpenRead(fileName);
FileStream fr = File.Create(gipFileName);
GZipStream gzs = new GZipStream(fr, CompressionMode.Compress); //压缩文件类
/*
int thebyte=fc.ReadByte();
while(thebyte!=-1)
{
gzs.WriteByte((byte)thebyte);
thebyte=fc.ReadByte();
}
*/
byte []arr = new byte[fc.Length];
fc.Read(arr, 0, (int)fc.Length);
gzs.Write(arr, 0, (int)fc.Length);
gzs.Close();
fc.Close();
fr.Close();
}
//解压缩文件方法
public static void DeZGip(string fileName, string gipFileName){
//准备输入输出文件
FileStream fc = File.Create(fileName);
FileStream fr = File.OpenRead(gipFileName);
GZipStream gzs = new GZipStream(fr, CompressionMode.Decompress);
byte[] arr = new byte[fr.Length];fr.Read(arr, 0, (int)fr.Length);
fc.Write(arr, 0, (int)fr.Length);
gzs.Close();
fr.Close();
fc.Close();
}