Java byte array and String mutual transfer creationtime--2018 July 6 14:53 author:marydon1.string-->byte[]
Method: Use String.getbytes (charset) to implement
String website = "http://www.cnblogs.com/Marydon20170307"; // string-->byte[], and specify the character set byte [] B = website.getbytes ("Utf-8"); // Print Conversion Results System.out.println (arrays.tostring (b));
2.byte[]-->string
Method: Use new String (Byte[],charset) to implement
// byte[]-->string, and specify the character set New String (b, "Utf-8"); // determine if the converted string is consistent with the source string System.out.println (transferresult.equals (website)); // true
3. Note
When a string and byte are converted to each other, the character set is best declared and needs to be consistent.
Related recommendations:
- Conversion between Java byte array and 16 binary
- Java Arrays Array
The Java byte array and string are transferred to each other