title: Binary file I/O
body: <p>How to read and write to binary files in D language? In C would be:</p>
  
  <pre><code>
      FILE *fp = fopen("/home/peu/Desktop/bla.bin", "wb");
      char x[4] = "RIFF";
  
      fwrite(x, sizeof(char), 4, fp);
  </code></pre>
  
  <p>I found rawWrite at D <a href="http://www.digitalmars.com/d/2.0/phobos/std_stdio.html#rawWrite" rel="noreferrer">docs</a>, but I don't know the usage, nor if does what I think. <code>fread</code> is from C:</p>
  
  <blockquote>
    <p><strong>T[] rawRead(T)(T[] buffer);</strong></p>
    
    <blockquote>
      <p>If the file is not opened, throws an exception. Otherwise, calls <em>fread</em> for the file handle and throws on error.</p>
      
      <p>rawRead always read in binary mode on Windows.</p>
    </blockquote>
  </blockquote>