title: Converting BinHex file to normal file using Java
body: <p>I have a binhex file. This file should be converted to normal readable file using java code.
  I found a similar question here,</p>
  
  <p><a href="https://stackoverflow.com/questions/12467973/binhex-decoding-using-java-code">Binhex decoding using java code</a></p>
  
  <p>But the answer is not working. </p>
  
  <p>I tried Base64, the file is converted to some other format which is not human readable.</p>
  
  <p>Please help me to resolve this issue.</p>
  
  <p>The code i tried is as below</p>
  
  <pre><code>File f = new File("Sample.pdf");
  Base64 base64 = new Base64();
  byte[] b = base64.decode(getBytesFromFile(f));          
  FileOutputStream fos = new FileOutputStream("Dcode.pdf");           
  fos.write(b);
  fos.close();
  
  public static byte[] getBytesFromFile(File file) throws IOException {
      InputStream is = new FileInputStream(file);
      long length = file.length();
      byte[] bytes = new byte[(int)length];
      int offset = 0;
      int numRead = 0;
      while (offset &lt; bytes.length &amp;&amp; (numRead=is.read(bytes, offset, bytes.length-offset)) &gt;= 0) 
      {
          offset += numRead;
      }
      if (offset &lt; bytes.length) {
          throw new IOException("Could not completely read file "+file.getName());
      }
      is.close();
      return bytes;
  }
  </code></pre>
  
  <p>The file Sample.pdf is BinHex ecoded. I want the file to be decoded.</p>