我有以下來源:如何知道C#中BinaryReader的當前偏移量?
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在偏移。
得到的位置不要注意,您做出強烈的假設,即BinaryReader在不從基礎緩衝區的字節流。它會緩衝字節。但不是以一種會以字節爲單位的方式。 –