Here you can find the source of bytesToString(byte[] bytes, int startIndex)
Parameter | Description |
---|---|
bytes | the byte array |
startIndex | the starting index where the string is stored, the first cell stores the length |
public static String bytesToString(byte[] bytes, int startIndex)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w .j a v a2 s .c om*/ * Given a byte array, restore a String out of it. the first cell stores the length of the String * * @param bytes * the byte array * @param startIndex * the starting index where the string is stored, the first cell stores the length * @ret the string out of the byte array. */ public static String bytesToString(byte[] bytes, int startIndex) { int len = (int) (bytes[startIndex++]) & 0xff; return new String(bytes, startIndex, len); } }