Java Byte Array to String bytesToString(byte[] buffer, int index, int length)

Here you can find the source of bytesToString(byte[] buffer, int index, int length)

Description

This function converts the bytes in a byte array at the specified index to its corresponding string value.

License

Open Source License

Parameter

Parameter Description
buffer The byte array containing the string.
index The index for the first byte in the byte array.
length The number of bytes that make up the string.

Return

The corresponding string value.

Declaration

static public String bytesToString(byte[] buffer, int index, int length) 

Method Source Code

//package com.java2s;
/************************************************************************
 * Copyright (c) Crater Dog Technologies(TM).  All Rights Reserved.     *
 ************************************************************************
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.        *
 *                                                                      *
 * This code is free software; you can redistribute it and/or modify it *
 * under the terms of The MIT License (MIT), as published by the Open   *
 * Source Initiative. (See http://opensource.org/licenses/MIT)          *
 ************************************************************************/

public class Main {
    /**//from ww  w.ja va2s  . co m
     * This function converts the bytes in a byte array to its corresponding string value.
     *
     * @param buffer The byte array containing the string.
     * @return The corresponding string value.
     */
    static public String bytesToString(byte[] buffer) {
        return bytesToString(buffer, 0, buffer.length);
    }

    /**
     * This function converts the bytes in a byte array at the specified index to its
     * corresponding string value.
     *
     * @param buffer The byte array containing the string.
     * @param index The index for the first byte in the byte array.
     * @param length The number of bytes that make up the string.
     * @return The corresponding string value.
     */
    static public String bytesToString(byte[] buffer, int index, int length) {
        return new String(buffer, index, length);
    }
}

Related

  1. bytesToStrHex(byte[] bytes)
  2. bytesToString(byte... bytes)
  3. bytesToString(byte[] arr)
  4. bytesToString(byte[] arr, int pos)
  5. bytesToString(byte[] b)
  6. bytesToString(byte[] bytes)
  7. bytesToString(byte[] bytes)
  8. bytesToString(byte[] bytes)
  9. bytesToString(byte[] bytes)