Tôi đã thực hiện một số phương pháp nhanh để viết tệp từ luồng nhưng chưa hoàn thành. Tôi nhận được ngoại lệ này và tôi không thể tìm thấy lý do:Không thể đọc ngoài phần cuối luồng
Unable to read beyond the end of the stream
Có ai có thể giúp tôi gỡ lỗi không?
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;
}
Cảm ơn rất nhiều!
Tuyệt vời, đơn giản hơn nhiều như bạn đã nói! Cảm ơn rất nhiều :-) – TomShreds