Java IO Tutorial - Java FileChannel.write(ByteBuffer src)








Syntax

FileChannel.write(ByteBuffer src) has the following syntax.

public abstract int write(ByteBuffer src)   throws IOException

Example

In the following code shows how to use FileChannel.write(ByteBuffer src) method.

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
/*ww w  . j  a v  a 2  s.  c om*/
public class Main {
  private static final int BSIZE = 1024;

  public static void main(String[] args) throws Exception {
    FileChannel fc = new RandomAccessFile("data.txt", "rw").getChannel();
    fc.position(fc.size());
    fc.write(ByteBuffer.wrap("Some more".getBytes()));
    fc.close();

  }
}