在 JAVA 中将 int 字节数组转换为 String

Convert int array of byte to String in JAVA

我有以下问题:

我有 2 个 int 的数组 - 它的字符 ř 我如何将这个数组转换为 stringchar

数组中的实际值为:[-59, -103]

ř->[-59, -103]->ř 谢谢。

编辑:

    String specialChar = "ř";
    System.out.println(specialChar);
    byte[] tmp = specialChar.getBytes();
    System.out.println(Arrays.toString(tmp)); //[-59, -103]
    int[] byteIntArray = new int[2];
    byteIntArray[0] = (int) tmp[0];
    byteIntArray[1] = (int) tmp[1];
    System.out.println(Arrays.toString(byteIntArray)); //[-59, -103]
    //now i want convert byteIntArray to string

那个呢?

byte[] byteArray = new byte[2];
byteArray[0] = (byte)byteIntArray[0];
byteArray[1] = (byte)byteIntArray[1];
String specialChar = new String(byteArray);

请注意,String.getBytes() 使用您的本地平台编码将字符串转换为字节数组。因此生成的字节数组取决于您的个人系统设置。

如果您希望字节数组与其他系统兼容,请改用 "UTF-8" 等标准编码:

byte[] tmp = specialChar.getBytes("UTF-8"); // String -> bytes
String s = new String(tmp, "UTF-8");        // bytes -> String