0
short[,] out2 = new short[1201, 1201];

FileStream fs = new FileStream(Application.StartupPath + "\\One_File\\result.hgt",
                               FileMode.OpenOrCreate, 
                               FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fs);

for (int i = 0; i < 1201; i++)
{
  for (int j = 0; j < 1201; j++)
  {
    bw.Write(out2[i, j]);
  }
}

1201 * 1201 * 2 = 2 884 802 bytes.

The size of the result file is 2 883 584 bytes.

Why?

Lewis86
  • 511
  • 6
  • 15
cybergogic
  • 33
  • 1
  • 6
  • 3
    I would guess you're inspecting the contents before you've closed/disposed the stream in your code. `2883584` is a suspiciously round number in binary. – Damien_The_Unbeliever Oct 22 '18 at 09:20
  • Did you close the file before inspecting it? If you put `using (FileStream fs = …) { … }` it will be deterministically flushed and closed when the using block ends so that is recommended practice. – Martin Liversage Oct 22 '18 at 09:21
  • Also if you smells like an `IDisposable`, use a `using` statement – TheGeneral Oct 22 '18 at 09:31
  • Also you should do `using (BinaryWriter bw = new BinaryWriter(fs)) { ... }`. – ckuri Oct 22 '18 at 10:30

0 Answers0