问题
I have source below:
public static void DisplayValues()
{
float aspectRatio;
string tempDirectory;
int autoSaveTime;
bool showStatusBar;
if (File.Exists(fileName))
{
using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
{
aspectRatio = reader.ReadSingle();
tempDirectory = reader.ReadString();
------------------------------------------------> I want to know current offset.
autoSaveTime = reader.ReadInt32();
showStatusBar = reader.ReadBoolean();
}
Console.WriteLine("Aspect ratio set to: " + aspectRatio);
Console.WriteLine("Temp directory is: " + tempDirectory);
Console.WriteLine("Auto save time set to: " + autoSaveTime);
Console.WriteLine("Show status bar: " + showStatusBar);
}
}
I have to find out current offset of BinaryReader.
回答1:
You can obtain the underlying stream by
var stream = reader.BaseStream;
and get the position by
stream.Position
回答2:
BinaryReader br=null;
/ * init, read, ...*/
long pos=br.BaseStream.Position;
来源:https://stackoverflow.com/questions/21969045/how-do-i-know-current-offset-of-binaryreader-in-c