all
I am very new to handle with binary data.
I am looking into some codes from MSDN.
Server side:
string fileName = "AppSettings.dat";
using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
writer.Write(1.250F);
writer.Write(@"c:\Temp");
writer.Write(10);
writer.Write(true);
}
And I received the binary file from server.
string clientFile = "AppSettings.dat";
using (BinaryReader reader = new BinaryReader(File.Open(clientFile, FileMode.Open)))
{
float aspectRatio = reader.ReadSingle();
string tempDirectory = reader.ReadString();
int autoSaveTime = reader.ReadInt32();
bool showStatusBar = reader.ReadBoolean();
}
It seems pretty easy to read and write when you use BinaryWriter and BinaryReader class.
But, here is my problem.
The server developer left the company, and somehow nobody is able to contact to him.
I cannot figure out how he wrote to BinaryWriter.
I mean the exact order.
In the example, I have to read reader in order as
ReadSingle
ReadString
ReadInt32
ReadBoolean
Then I can get the correct result.
But in my situation, I don't know the exact order.
So, what I can try is how to read all the characters and numbers at once.
Like......
string contents = reader.someMethod;
Then contents is like below:
1.250F
c:\Temp
10
true
The carriage return is skippable.
EDIT
I have tried File.ReadAllBytes.
But the result is not what I expected to be...
byte[] bytes = System.IO.File.ReadAllBytes(clientFile);
string contents = Encoding.UTF8.GetString(bytes);
\0\0�?\ac:\Temp\n\0\0\0