Dart API Referencedart:ioRandomAccessFile

RandomAccessFile abstract class

RandomAccessFile provides random access to the data in a file. RandomAccessFile objects are obtained by calling the open method on a File object.

abstract class RandomAccessFile {
  /**
   * Close the file. Returns a [:Future<RandomAccessFile>:] that
   * completes with this RandomAccessFile when it has been closed.
   */
  Future<RandomAccessFile> close();

  /**
   * Synchronously close the file.
   */
  void closeSync();

  /**
   * Read a byte from the file. Returns a [:Future<int>:] that
   * completes with the byte or -1 if end of file has been reached.
   */
  Future<int> readByte();

  /**
   * Synchronously read a single byte from the file. If end of file
   * has been reached -1 is returned.
   */
  int readByteSync();

  /**
   * Read a List<int> from the file. Returns a [:Future<int>:] that
   * completes with an indication of how much was read.
   */
  Future<int> readList(List<int> buffer, int offset, int bytes);

  /**
   * Synchronously read a List<int> from the file. Returns the number
   * of bytes read.
   */
  int readListSync(List<int> buffer, int offset, int bytes);

  /**
   * Write a single byte to the file. Returns a
   * [:Future<RandomAccessFile>:] that completes with this
   * RandomAccessFile when the write completes.
   */
  Future<RandomAccessFile> writeByte(int value);

  /**
   * Synchronously write a single byte to the file. Returns the
   * number of bytes successfully written.
   */
  int writeByteSync(int value);

  /**
   * Write a List<int> to the file. Returns a
   * [:Future<RandomAccessFile>:] that completes with this
   * RandomAccessFile when the write completes.
   */
  Future<RandomAccessFile> writeList(List<int> buffer, int offset, int bytes);

  /**
   * Synchronously write a List<int> to the file. Returns the number
   * of bytes successfully written.
   */
  int writeListSync(List<int> buffer, int offset, int bytes);

  /**
   * Write a string to the file using the given [encoding]. Returns a
   * [:Future<RandomAccessFile>:] that completes with this
   * RandomAccessFile when the write completes.
   */
  Future<RandomAccessFile> writeString(String string,
                                       [Encoding encoding = Encoding.UTF_8]);

  /**
   * Synchronously write a single string to the file using the given
   * [encoding]. Returns the number of characters successfully
   * written.
   */
  int writeStringSync(String string,
                      [Encoding encoding = Encoding.UTF_8]);

  /**
   * Get the current byte position in the file. Returns a
   * [:Future<int>:] that completes with the position.
   */
  Future<int> position();

  /**
   * Synchronously get the current byte position in the file.
   */
  int positionSync();

  /**
   * Set the byte position in the file. Returns a
   * [:Future<RandomAccessFile>:] that completes with this
   * RandomAccessFile when the position has been set.
   */
  Future<RandomAccessFile> setPosition(int position);

  /**
   * Synchronously set the byte position in the file.
   */
  void setPositionSync(int position);

  /**
   * Truncate (or extend) the file to [length] bytes. Returns a
   * [:Future<RandomAccessFile>:] that completes with this
   * RandomAccessFile when the truncation has been performed.
   */
  Future<RandomAccessFile> truncate(int length);

  /**
   * Synchronously truncate (or extend) the file to [length] bytes.
   */
  void truncateSync(int length);

  /**
   * Get the length of the file. Returns a [:Future<int>:] that
   * completes with the length in bytes.
   */
  Future<int> length();

  /**
   * Synchronously get the length of the file.
   */
  int lengthSync();

  /**
   * Flush the contents of the file to disk. Returns a
   * [:Future<RandomAccessFile>:] that completes with this
   * RandomAccessFile when the flush operation completes.
   */
  Future<RandomAccessFile> flush();

  /**
   * Synchronously flush the contents of the file to disk.
   */
  void flushSync();

  /**
   * Get the name of the file.
   */
  String get name;
}

Properties

final String name #

Get the name of the file.

String get name;

Methods

Future<RandomAccessFile> close() #

Close the file. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when it has been closed.

Future<RandomAccessFile> close();

void closeSync() #

Synchronously close the file.

void closeSync();

Future<RandomAccessFile> flush() #

Flush the contents of the file to disk. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the flush operation completes.

Future<RandomAccessFile> flush();

void flushSync() #

Synchronously flush the contents of the file to disk.

void flushSync();

Future<int> length() #

Get the length of the file. Returns a Future<int> that completes with the length in bytes.

Future<int> length();

int lengthSync() #

Synchronously get the length of the file.

int lengthSync();

Future<int> position() #

Get the current byte position in the file. Returns a Future<int> that completes with the position.

Future<int> position();

int positionSync() #

Synchronously get the current byte position in the file.

int positionSync();

Future<int> readByte() #

Read a byte from the file. Returns a Future<int> that completes with the byte or -1 if end of file has been reached.

Future<int> readByte();

int readByteSync() #

Synchronously read a single byte from the file. If end of file has been reached -1 is returned.

int readByteSync();

Future<int> readList(List<int> buffer, int offset, int bytes) #

Read a List<int> from the file. Returns a Future<int> that completes with an indication of how much was read.

Future<int> readList(List<int> buffer, int offset, int bytes);

int readListSync(List<int> buffer, int offset, int bytes) #

Synchronously read a List<int> from the file. Returns the number of bytes read.

int readListSync(List<int> buffer, int offset, int bytes);

Future<RandomAccessFile> setPosition(int position) #

Set the byte position in the file. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the position has been set.

Future<RandomAccessFile> setPosition(int position);

void setPositionSync(int position) #

Synchronously set the byte position in the file.

void setPositionSync(int position);

Future<RandomAccessFile> truncate(int length) #

Truncate (or extend) the file to length bytes. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the truncation has been performed.

Future<RandomAccessFile> truncate(int length);

void truncateSync(int length) #

Synchronously truncate (or extend) the file to length bytes.

void truncateSync(int length);

Future<RandomAccessFile> writeByte(int value) #

Write a single byte to the file. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the write completes.

Future<RandomAccessFile> writeByte(int value);

int writeByteSync(int value) #

Synchronously write a single byte to the file. Returns the number of bytes successfully written.

int writeByteSync(int value);

Future<RandomAccessFile> writeList(List<int> buffer, int offset, int bytes) #

Write a List<int> to the file. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the write completes.

Future<RandomAccessFile> writeList(List<int> buffer, int offset, int bytes);

int writeListSync(List<int> buffer, int offset, int bytes) #

Synchronously write a List<int> to the file. Returns the number of bytes successfully written.

int writeListSync(List<int> buffer, int offset, int bytes);

Future<RandomAccessFile> writeString(String string, [Encoding encoding = Encoding.UTF_8]) #

Write a string to the file using the given encoding. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the write completes.

Future<RandomAccessFile> writeString(String string,
                                     [Encoding encoding = Encoding.UTF_8]);

int writeStringSync(String string, [Encoding encoding = Encoding.UTF_8]) #

Synchronously write a single string to the file using the given encoding. Returns the number of characters successfully written.

int writeStringSync(String string,
                    [Encoding encoding = Encoding.UTF_8]);