title: Convert byte[] with binary data to String
body: <p>I have data in binary format (<code>hex: 80 3b c8 87 0a 89</code>) and I need to convert that into String in order to save binary data in MS Access db via Jackcess. I know, that I'm not suppose to use String in Java for binary data, however Access db is third party product and I have not control whatsoever. </p>
  
  <p>So I tried to convert binary data and save it, but unfortunately the result was unexpected. </p>
  
  <pre><code>byte[] byteArray = new byte[] {0x80, 0x3b, 0xc8, 0x87, 0x0a 0x89};
  System.out.println(String.format("%02X ",byteArray[0])+String.format("%02X ", byteArray[1]));//gives me the same values
  
  String value = new String(byteArray, "UTF-8");//or any other encoding
  System.out.println(value);//completely different values
  </code></pre>
  
  <p>I would like to know what going on under <code>new String</code> and if there is a way to convert binary data into String and have the same hex values.</p>
  
  <p><strong>Note 1</strong>: initially I read a binary file which has nothing to do with hex. I use hex just for comparison of datasets.</p>
  
  <p><strong>Note 2</strong> There was a suggestion to use Base64 aka MIME, UTF-7, etc. By my understanding, it takes binary data and encodes that into ANSI charset, basically tweaking initial data. However,for me that is not a solution, because I must write exact data that I hold in binary array.</p>
  
  <pre><code>byte[] byteArray = new byte[]{0x2f, 0x7a, 0x2d, 0x28};
  byte[]   bytesEncoded = Base64.encodeBase64(byteArray);
  System.out.println("encoded value is " + new String(bytesEncoded ));//new data
  </code></pre>