我正在打开一个相当小的文件(大约200 kb),然后在一个BufferedStream中打开它,因为我将多次阅读它。当我尝试创建BufferedStream时,我会得到一个IOException:
var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true);
using (var bfs = new BufferedStream(stream)); // IOException: An attempt was made to move the file pointer before the beginning of the file.是什么导致IO异常?我的应用程序正在使用.NET 4.6
发布于 2016-05-17 14:39:01
这并不能具体回答您的问题,但您不需要使用BufferedStream。缓冲已经被编织到FileStream中。
请参阅https://blogs.msdn.microsoft.com/brada/2004/04/15/filestream-and-bufferedstream/
特别值得一提的是以下几句话:
答案(来自,System.IO命名空间的dev ): 不,将BufferedStream封装在FileStream上没有任何好处。大约4年前,我们将BufferedStream的缓冲逻辑复制到FileStream中,以鼓励更好的默认性能(成功之处)。事实上,我不认为.NET框架中有任何流需要它,但是如果它们在默认情况下不进行缓冲,那么定制的Stream实现可能需要它。
https://stackoverflow.com/questions/37279119
复制相似问题