read Bytes from FileChannel - Java java.nio.channels

Java examples for java.nio.channels:FileChannel

Description

read Bytes from FileChannel

Demo Code


//package com.java2s;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Main {
    public static byte[] readBytes(int offset, FileChannel fc,
            ByteBuffer buffer) throws IOException {
        fc.position(offset);/*from  w  w w. j  a  v  a 2 s  . c  o  m*/
        buffer.clear();
        fc.read(buffer);
        return buffer.array();
    }
}

Related Tutorials