我做了一些快速的方法來從流中寫入文件,但尚未完成。我收到這個例外,我找不到原因:無法讀取超過流末尾
Unable to read beyond the end of the stream
有沒有人可以幫我調試它?
public static bool WriteFileFromStream(Stream stream, string toFile)
{
FileStream fileToSave = new FileStream(toFile, FileMode.Create);
BinaryWriter binaryWriter = new BinaryWriter(fileToSave);
using (BinaryReader binaryReader = new BinaryReader(stream))
{
int pos = 0;
int length = (int)stream.Length;
while (pos < length)
{
int readInteger = binaryReader.ReadInt32();
binaryWriter.Write(readInteger);
pos += sizeof(int);
}
}
return true;
}
非常感謝!
令人驚歎,像你說的那麼簡單!非常感謝 :-) – TomShreds