我的原始文件是 .zip zip中有个文件夹,文件夹下是需要的文件.txt
通过gzip下载到本地,然后通过GZipStream 解压文件
高手来帮忙解决一下
我在网上找到这个
public static string DeCompress(string fileName, string dirPath)
{
string iid = string.Empty;
using (Stream source = File.OpenRead(fileName))
{
using (Stream destination = new MemoryStream())
{
using (GZipStream input = new GZipStream(source, CompressionMode.Decompress, true))
{
byte[] bytes = new byte[4096 * 100];
int n = input.Read(bytes, 0, bytes.Length);
if (n > 0)
{
destination.Write(bytes, 0, n);
}
}
destination.Flush();
destination.Position = 0;
DeSerializeFiles(destination, dirPath);
}
}
return iid;
}
private static void DeSerializeFiles(Stream s, string dirPath)
{
BinaryFormatter b = new BinaryFormatter();
ArrayList list = (ArrayList)b.Deserialize(s);
foreach (SerializeFileInfo f in list)
{
string newName = dirPath + Path.GetFileName(f.FileName);
using (FileStream fs = new FileStream(newName, FileMode.Create, FileAccess.Write))
{
fs.Write(f.FileBuffer, 0, f.FileBuffer.Length);
fs.Close();
}
}
}
标红出有异常,不知道怎么解决了
http://icsharpcode.github.io/SharpZipLib/
哦,这几天忙别的了,嗯,我不想用第三方的dll