Java File Read via ByteBuffer getReadBuffer(File file)

Here you can find the source of getReadBuffer(File file)

Description

get Read Buffer

License

Open Source License

Declaration

public static ByteBuffer getReadBuffer(File file) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;
import java.nio.*;

import java.nio.channels.FileChannel.MapMode;

public class Main {

    public static ByteBuffer getReadBuffer(File file) {
        try (RandomAccessFile f = new RandomAccessFile(file, "r")) {
            return f.getChannel().map(MapMode.READ_ONLY, 0, file.length());
        } catch (IOException e) {
            return null;
        }/* w  w w.j ava  2s .c o  m*/
    }

    public static ByteBuffer getReadBuffer(String file) {
        return getReadBuffer(new File(file));
    }
}

Related

  1. copy(final ReadableByteChannel src, final WritableByteChannel dest)
  2. copy(final ReadableByteChannel srcChannel, final WritableByteChannel destChannel)
  3. copyChannel(int bufferSize, ReadableByteChannel source, WritableByteChannel destination)
  4. copyStream(BufferedReader reader, BufferedWriter writer)
  5. count(final ReadableByteChannel src)
  6. getStringContents(ReadableByteChannel channel)
  7. largeFileReader(String filename)
  8. mapReadWrite(File file)
  9. nioCopy(ReadableByteChannel input, WritableByteChannel output)