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  av  a  2s  .co  m
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();

  }
}




















Home »
  Java Tutorial »
    java.nio.channels »




FileChannel