RandomAccessFile: getFilePointer()
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());
}
}
Home
Java Book
File Stream
Java Book
File Stream
RandomAccessFile:
- RandomAccessFile
- new RandomAccessFile(String fileName, String mode)
- RandomAccessFile: close()
- RandomAccessFile: getChannel()
- RandomAccessFile: getFilePointer()
- RandomAccessFile: length()
- RandomAccessFile: read(byte[] b)
- RandomAccessFile: readBoolean()
- RandomAccessFile: readByte()
- RandomAccessFile: readChar()
- RandomAccessFile: readDouble()
- RandomAccessFile: readInt()
- RandomAccessFile: readLine()
- RandomAccessFile: seek(long pos)
- RandomAccessFile: write(byte[] b)
- RandomAccessFile: writeBoolean(boolean v)
- RandomAccessFile: writeBytes(String s)
- RandomAccessFile: writeChars(String s)
- RandomAccessFile: writeInt(int v)
- RandomAccessFile: writeUTF(String str)