FileChannel: position() : FileChannel « java.nio.channels « Java by API






FileChannel: position()

 

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

public class Main {
  public static void main(String[] argv) throws IOException {
    RandomAccessFile randomAccessFile = new RandomAccessFile("test.dat", "r");

    randomAccessFile.seek(1000);

    FileChannel fileChannel = randomAccessFile.getChannel();

    // This will print "1000"
    System.out.println("file pos: " + fileChannel.position());

    randomAccessFile.seek(500);

    // This will print "500"
    System.out.println("file pos: " + fileChannel.position());

    fileChannel.position(200);

    // This will print "200"
    System.out.println("file pos: " + randomAccessFile.getFilePointer());
  }
}

   
  








Related examples in the same category

1.FileChannel.MapMode.READ_ONLY
2.FileChannel.MapMode.READ_WRITE
3.FileChannel: close()
4.FileChannel: lock(long position, long size, boolean shared)
5.FileChannel: map(MapMode mode, long position, long size)
6.FileChannel: position(long newPosition)
7.FileChannel: read(ByteBuffer dst)
8.FileChannel: size()
9.FileChannel: transferFrom(ReadableByteChannel src, long position, long count)
10.FileChannel: transferTo(long position, long count, WritableByteChannel target)
11.FileChannel: tryLock()
12.FileChannel: write(MappedByteBuffer buffer)
13.FileChannel: write(ByteBuffer buffer)