我基本上是从msdn直接复制了这段代码示例,并做了一些最小的修改。 CopyTo
方法默默无闻,我不知道为什么。什么会导致这种行为?它传递一个78 KB的压缩文件夹,其中包含一个文本文件。返回的FileInfo
对象指向一个0 KB文件。没有例外被抛出。DeflateStream CopyTo不写任何东西,也不会抛出异常
public static FileInfo DecompressFile(FileInfo fi)
{
// Get the stream of the source file.
using (FileStream inFile = fi.OpenRead())
{
// Get original file extension,
// for example "doc" from report.doc.cmp.
string curFile = fi.FullName;
string origName = curFile.Remove(curFile.Length
- fi.Extension.Length);
//Create the decompressed file.
using (FileStream outFile = File.Create(origName))
{
// work around for incompatible compression formats found
// here http://george.chiramattel.com/blog/2007/09/deflatestream-block-length-does-not-match.html
inFile.ReadByte();
inFile.ReadByte();
using (DeflateStream Decompress = new DeflateStream(inFile,
CompressionMode.Decompress))
{
// Copy the decompression stream
// into the output file.
Decompress.CopyTo(outFile);
return new FileInfo(origName);
}
}
}
}
什么类型的文件正在尝试读取和解压缩? .gz,.zip或其他内容? – huntharo
@huntharo它是一个.zip。 – evanmcdonnal