我的来源如下:
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);
}
}
我必须找出BinaryReader的当前偏移量。
答案 0 :(得分:9)
您可以通过
获取基础流var stream = reader.BaseStream;
并通过
获得职位stream.Position
答案 1 :(得分:1)
BinaryReader br=null;
/ * init, read, ...*/
long pos=br.BaseStream.Position;