使用ByteBuffer从通道读取
import java.io.FileInputStream; import java.nio.ByteBuffer; import java.nio.channels.ReadableByteChannel; /* from NowJava.com - 时代Java*/ public class Main { public static void main(String[] argv) { try { // Obtain a channel ReadableByteChannel channel = new FileInputStream("infile").getChannel(); // Create a direct ByteBuffer; see also Creating a ByteBuffer ByteBuffer buf = ByteBuffer.allocateDirect(10); int numRead = 0;/*NowJava.com - 时 代 Java 提 供*/ while (numRead >= 0) { buf.rewind(); // Read bytes from the channel numRead = channel.read(buf); buf.rewind(); for