首页 > 编程语言 >java修剪字节组

java修剪字节组

时间:2022-12-21 14:34:47浏览次数:45  
标签:index 修剪 java 字节 result byte data String

    public static String byteArrToString(byte[] data, String encoding) throws UnsupportedEncodingException {
        int index = -1;
        for (byte t : data) {
            if (t != 0) {
                index++;
            }
        }
        byte[] result = new byte[index + 1];
        System.arraycopy(data, 0, result, 0, index + 1);
        return new String(result, encoding);
    }

标签:index,修剪,java,字节,result,byte,data,String
From: https://www.cnblogs.com/hhddd-1024/p/16996196.html

相关文章