title: Programmatically Create MP3
body: <p>I'm trying to create my own MP3 audio file. How would I go about doing this?</p>
  
  <pre><code>File mySong = new File("generated song.mp3"); 
  FileOutputStream song = new FileOutputStream(mySong);
  for (int n = 0; n &lt; 3000; n++){
      song.write(n % 256);
  }
  song.close();
  </code></pre>
  
  <p>I tried the above code, but Windows gave me an error when I tried playing it back. I imagine there must be some beginning and ending sequence of bytes that I need to write to the file in order for it to be properly decoded. So, how could I generate my own .MP3 file?</p>