Java tutorial
//package com.java2s; public class Main { public static String bytesToString(byte[] bytes, int offset, int strLength) { byte[] stringBytes = new byte[strLength]; System.arraycopy(bytes, offset, stringBytes, 0, strLength); // return new String(Arrays.copyOfRange(bytes, offset, offset + strLength)).trim(); return new String(stringBytes).trim(); } }