Java FileChannel get from RandomAccessFile for read and write

Description

Java FileChannel get from RandomAccessFile for read and write

import java.io.File;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Main {
  public static void main(String[] argv) throws Exception {
    FileChannel rwChannel = new RandomAccessFile(new File("test.txt"), "rw").getChannel();
    ByteBuffer wrBuf = rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, (int) rwChannel.size());
  }/*from w w w.ja v  a 2  s .c  om*/
}



PreviousNext

Related