Copy byte array by range - Android File Input Output

Android examples for File Input Output:Byte Array Copy

Description

Copy byte array by range

Demo Code


//package com.book2s;

public class Main {

    public static byte[] copyOfRange(byte[] original, int from, int to) {
        int newLength = to - from;
        if (newLength < 0)
            throw new IllegalArgumentException(from + " > " + to);
        byte[] copy = new byte[newLength];
        System.arraycopy(original, from, copy, 0,
                Math.min(original.length - from, newLength));
        return copy;
    }/*from w  w  w .  j a  v a2 s. com*/
}

Related Tutorials