如果我使用 StreamReader 和 StreamWriter 读写二进制文件,该文件可以修复吗?
// Original Code - Corrupted the Destination File
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(responseStream))
{
using (StreamWriter writer = new StreamWriter(destinationFileName, false))
{
writer.Write(reader.ReadToEnd());
}
}
}
// New Code - Destination File is Good
using (Stream responseStream = response.GetResponseStream())
{
using (FileStream fs = File.Create(destinationFileName))
{
responseStream.CopyTo(fs);
}
}