如何使用 FileStream 将光标移回 1 个读数?
How to move cursor back 1 reading with FileStream?
我在 FileStream
中逐字节读取。我用 ReadByte
.
我总是需要检查下一个字节。如果我读取某个字节,我希望能够返回一个字节。
原因是遇到这个字节,我需要把FileStream
传给另一个函数,但是它需要在这个特定的前一个位置(后一个字节)读取它。
我怎样才能做到这一点?
确实我搜索了 https://www.bing.com/search?q=c%23+change+position+to+previous+stream+site%3awhosebug.com but all questions suggest to use Seek(offset, Beginning)
. Some user suggested duplicate which shows how to use .Seek(0, SeekOrigin.Begin);
- that definitely what I want. I need to seek to current position (for which I found plausible method be searching for "C# filestream position" - FileStream.Position) 减少了一个
有Seek
method to set the stream to a given position. You can get the current position of the stream with the Position
property.
那么应该是这样的:
fileStream.Seek(filestream.Position - 1, SeekOrigin.Begin);
我在 FileStream
中逐字节读取。我用 ReadByte
.
我总是需要检查下一个字节。如果我读取某个字节,我希望能够返回一个字节。
原因是遇到这个字节,我需要把FileStream
传给另一个函数,但是它需要在这个特定的前一个位置(后一个字节)读取它。
我怎样才能做到这一点?
确实我搜索了 https://www.bing.com/search?q=c%23+change+position+to+previous+stream+site%3awhosebug.com but all questions suggest to use Seek(offset, Beginning)
. Some user suggested duplicate which shows how to use .Seek(0, SeekOrigin.Begin);
- that definitely what I want. I need to seek to current position (for which I found plausible method be searching for "C# filestream position" - FileStream.Position) 减少了一个
有Seek
method to set the stream to a given position. You can get the current position of the stream with the Position
property.
那么应该是这样的:
fileStream.Seek(filestream.Position - 1, SeekOrigin.Begin);