read Byte from FileChannel - Java java.nio.channels

Java examples for java.nio.channels:FileChannel

Description

read Byte 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 readByte(int offset, FileChannel fc,
            ByteBuffer buffer) throws IOException {
        return readBytes(offset, fc, buffer)[0];
    }//from w w  w. jav  a  2  s.c o m

    public static byte[] readBytes(int offset, FileChannel fc,
            ByteBuffer buffer) throws IOException {
        fc.position(offset);
        buffer.clear();
        fc.read(buffer);
        return buffer.array();
    }
}

Related Tutorials