
This article explain how to convert byte array to String.
Byte Array to String code
public class ByteArrayToString { public static void main(String[] args) { byte[] byteArray= {67,111,100,101,32, 66,108,111,103,32, 77,111,110,101,121}; //Convert byte[] to String String convertedToString = new String(byteArray); System.out.println("Byte Array to String : " + convertedToString); } }
Output
Byte Array to String : Code Blog Money
String to Byte Array
public class StringtoByteArray { public static void main(String[] args) { String sampleString = "CodeBlogMoney"; byte[] byteArray = sampleString.getBytes(); System.out.println("Byte Array data :\n"); for(byte b : byteArray) { System.out.print(b + " "); } } }
Output
Byte Array data : 67 111 100 101 66 108 111 103 77 111 110 101 121