Hi @Zed Yang ,
Please put decompressor. CopyTo(outputFileStream);
in curly brackets after the Using statement to prevent the stream from being closed prematurely.
private static void DecompressFile()
{
using (FileStream compressedFileStream = File.Open(CompressedFileName, FileMode.Open))
using (FileStream outputFileStream = File.Create(DecompressedFileName))
using (GZipStream decompressor = new GZipStream(compressedFileStream, CompressionMode.Decompress))
{
decompressor.CopyTo(outputFileStream);
}
}
Also try to use the TryCatch statement to catch possible exceptions.
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.