The RandomAccessFile Class

RandomAccessFile both reads and writes to binary output streams. It's most similar to the Python file object and has the following methods:

  • __init__(strName, strMode)— opens the file in the specified mode

  • __init__(File, strMode)— same as above, but passes a Java file object

  • getFD()— gets the file descriptor

  • getFilePointer()— similar to the tell() method for the Python file object

  • length()— gets the length of the file

  • seek()— similar to the seek() method for the Python file object

  • read(byte_sequence)— similar to the read() method in InputStream

  • read(byte_sequence, off, len)— similar to the read() method in InputStream

The following abstract methods are from DataInput:

  • readBoolean()

  • readByte()

  • readFloat()

  • readChar()

  • readDouble() ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.