Java examples for java.nio.channels:ReadableByteChannel
Open a readable byte channel for a file.
//package com.java2s; import java.io.File; import java.io.FileNotFoundException; import java.io.RandomAccessFile; import java.nio.channels.ReadableByteChannel; public class Main { public static void main(String[] argv) throws Exception { File file = new File("Main.java"); System.out.println(openReadChannel(file)); }/*w ww . j a v a 2 s . co m*/ /** * Open a readable byte channel for a file. * * @param file * A <code>File</code>. * @return A <code>ReadableByteChannel</code>. * @throws FileNotFoundException */ public static ReadableByteChannel openReadChannel(final File file) throws FileNotFoundException { return new RandomAccessFile(file, "r").getChannel(); } }