This article explain how to convert byte array to String.
Byte Array to String code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
publicclassByteArrayToString{publicstaticvoidmain(String[]args){byte[]byteArray={67,111,100,101,32,66,108,111,103,32,77,111,110,101,121};//Convert byte[] to String StringconvertedToString=newString(byteArray);System.out.println("Byte Array to String : "+convertedToString);}}
Output
Byte Array to String : Code Blog Money
String to Byte Array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
publicclassStringtoByteArray{publicstaticvoidmain(String[]args){StringsampleString="CodeBlogMoney";byte[]byteArray=sampleString.getBytes();System.out.println("Byte Array data :\n");for(byteb:byteArray){System.out.print(b+" ");}}}
Sharing is caring!