我想将我的十六进制字符串转换为字节并将其保存到字节数组中。我在互联网上看到了代码并试图将其调整到我的程序中。但我完全不知所措。我对 java 很陌生。可以请帮助我进行转换。以下是我编写的代码。谢谢
public class Main {
static String s = "00e83901c829e3735cc04137f3598a2b565c67665446d46ee74a6fd4ff8f556c7272fb6aeda45a757639aee558b130442fd4ff3f5cf98a08d0da6a23216d192dfd24bdda08a0b1081ae59fba0ae1516a2e02989df6b17a513b08895705552950e14fe430da3eae58fcc70619a129b534bbed6a9abc39706b1884b85a628781a86cc5223f038a7c0b48e1cf94033f7c5f1637900559b38fe2ccf41a14df5b8d81388fcebc69b59f7bc85a1c3e8b34a6deeb04a1e7fb1d3a7ae59009ea002aaa6ba5cdb9fa45653ac5eb89f61d436934f992197dbdb4c4a212cd7fbcd231debda57f11943b7f66215ecd616a4eed13fc9e38cd41d571b9faf496053b50a50321a076393ad91832959347f1fe5efd18e6267377108382fd992216a439ddc3dc59ce0ea955de95db767de4877caeaf8c7c4718e906d59db492cd610e7a28056f";
public static void main(String[] args) {
}
private static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i/2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) +
Character.digit(s.charAt(i+1), 16));
}
return data;
}
}