- public void WritingABinaryBun()
- {
-
- System.IO.FileStream wFile;
- wFile = new FileStream(Path.Combine(OuputsPath, "SC03Brick201.bun"), FileMode.Create);
- byte[] bytes = BitConverter.GetBytes(-1);
- if (BitConverter.IsLittleEndian) Array.Reverse(bytes);
- wFile.Write(bytes, 0, bytes.Length);
-
- bytes = BitConverter.GetBytes(10);
- if (BitConverter.IsLittleEndian) Array.Reverse(bytes);
- wFile.Write(bytes, 0, bytes.Length);
-
- bytes = BitConverter.GetBytes(164);
- if (BitConverter.IsLittleEndian) Array.Reverse(bytes);
- wFile.Write(bytes, 0, bytes.Length);
- }
-
-
- public void ReadingABinaryBun()
- {
-
- using (BinaryReader b = new BinaryReader(File.Open(Path.Combine(InputsPath, "SC03Brick201.bun"), FileMode.Open)))
- {
-
- int pos = 0;
-
- int length = (int)b.BaseStream.Length;
-
-
- while (pos < length)
- {
- int v = b.ReadInt32();
-
-
- pos += sizeof(int);
-
-
-
- }
- }
-
-
-
- }
Below are 2 code snippets (which are a concise form of my code) which I'm using for writing and reading a binary file.
As you see, I have written 3 integer values into a binary file.
But when I read the same file through the second code snippet, I see only the foirst integer value of -1 is correctly read in.
Can anybody please help em understand why is it so?
I am using C#