bin2hex
? Java ??????,??????????????????????????????????????????????????????????,???????????????(???? new String(byteArray, sourceCharset)
),????????????????????(???? new String(string.getBytes(targetCharset))
)?
??????????,??????? bin2hex
???????????????,??????????????:
import java.nio.charset.Charset; import java.util.Arrays; public class Bin2HexExample { public static void main(String[] args) { byte[] byteArray = "Hello, world!".getBytes(Charset.forName("UTF-8")); String hexString = bin2hex(byteArray); System.out.println("Hex string: " + hexString); byte[] decodedByteArray = hexToBin(hexString); String decodedString = new String(decodedByteArray, Charset.forName("UTF-8")); System.out.println("Decoded string: " + decodedString); } public static String bin2hex(byte[] data) { StringBuilder sb = new StringBuilder(); for (byte b : data) { sb.append(String.format("x", b)); } return sb.toString(); } public static byte[] hexToBin(String hex) { int len = hex.length(); byte[] data = https://www.yisu.com/ask/new byte[len / 2];>??????,??? "Hello, world!" ???? UTF-8 ?????????????,???????? UTF-8 ??????,???????????,??????????????????????