title: convert base64 string into byte array and save in mp3 file format in java
body: <p>I am having a problem with writing an MP3 file on Linux.  Here is my situation:</p>
  
  <p>I have an XML message that is coming over JMS.  The XML has an element that is a Base64 encoded string which represents an MP3 audio file.  In marshalling the XML to Objects, I use JIBX. JIBX will then convert the Base64 encoded String to byte[].  I, then, write the byte[] to the file system using FileUtils from the commons-io project.  </p>
  
  <pre><code>void writeMP3File(final byte[] data, final String filePath) throws IOException {
  
      final File mp3File = new File(basePath + IOUtils.DIR_SEPARATOR + filePath);
  
      mp3File.getParentFile().mkdirs(); // Ensure any parent directories are created
  
      FileUtils.writeByteArrayToFile(mp3File, data);
  }
  </code></pre>
  
  <p>When I try to play the file later, the MP3 player will not play the file.  Also, when I go to the file system and look at the file, I get:</p>
  
  <blockquote>
    <p>> file TestFile1.mp3<br>
    TestFile1.mp3: ASCII text, with no line terminators</p>
  </blockquote>
  
  <p>I tried using FileOutputStream to write the file, as well; and the same result happens.  How do you write a byte[] to a file and set the file type of MPEG.  So, what I want to see on the file system is:</p>
  
  <blockquote>
    <p>> file TestFile1.mp3<br>
    TestFile1.mp3: MPEG ADTS, layer III,  v2.5,   8 kBits, 8 kHz, Monaural</p>
  </blockquote>