RandomAccessFile class

RandomAccessFile provides random access to the data in a file.

RandomAccessFile objects are obtained by calling the open method on a File object.

A RandomAccessFile have both asynchronous and synchronous methods. The asynchronous methods all return a Future whereas the synchronous methods will return the result directly, and block the current isolate until the result is ready.

At most one asynchronous method can be pending on a given RandomAccessFile instance at the time. If an asynchronous method is called when one is already in progress a FileSystemException is thrown.

If an asynchronous method is pending it is also not possible to call any synchronous methods. This will also throw a FileSystemException.

Constructors

RandomAccessFile()

Properties

path String
Gets the path of the file underlying this RandomAccessFile.
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

close() Future<void>
Closes the file. Returns a Future that completes when it has been closed.
closeSync() → void
Synchronously closes the file. [...]
flush() Future<RandomAccessFile>
Flushes the contents of the file to disk. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the flush operation completes.
flushSync() → void
Synchronously flushes the contents of the file to disk. [...]
length() Future<int>
Gets the length of the file. Returns a Future<int> that completes with the length in bytes.
lengthSync() int
Synchronously gets the length of the file. [...]
lock([FileLock mode = FileLock.exclusive, int start = 0 int end = -1 ]) Future<RandomAccessFile>
Locks the file or part of the file. [...]
lockSync([FileLock mode = FileLock.exclusive, int start = 0 int end = -1 ]) → void
Synchronously locks the file or part of the file. [...]
position() Future<int>
Gets the current byte position in the file. Returns a Future<int> that completes with the position.
positionSync() int
Synchronously gets the current byte position in the file. [...]
read(int bytes) Future<Uint8List>
Reads bytes bytes from a file and returns the result as a list of bytes.
readByte() Future<int>
Reads a byte from the file. Returns a Future<int> that completes with the byte, or with -1 if end-of-file has been reached.
readByteSync() int
Synchronously reads a single byte from the file. If end-of-file has been reached -1 is returned. [...]
readInto(List<int> buffer, [ int start = 0 int end ]) Future<int>
Reads into an existing List<int> from the file. If start is present, the bytes will be filled into buffer from at index start, otherwise index 0. If end is present, the end - start bytes will be read into buffer, otherwise up to buffer.length. If end == start nothing happens. [...]
readIntoSync(List<int> buffer, [ int start = 0 int end ]) int
Synchronously reads into an existing List<int> from the file. If start is present, the bytes will be filled into buffer from at index start, otherwise index 0. If end is present, the end - start bytes will be read into buffer, otherwise up to buffer.length. If end == start nothing happens. [...]
readSync(int bytes) Uint8List
Synchronously reads a maximum of bytes bytes from a file and returns the result in a list of bytes. [...]
setPosition(int position) Future<RandomAccessFile>
Sets the byte position in the file. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the position has been set.
setPositionSync(int position) → void
Synchronously sets the byte position in the file. [...]
toString() String
Returns a human-readable string for this RandomAccessFile instance.
override
truncate(int length) Future<RandomAccessFile>
Truncates (or extends) the file to length bytes. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the truncation has been performed.
truncateSync(int length) → void
Synchronously truncates (or extends) the file to length bytes. [...]
unlock([int start = 0 int end = -1 ]) Future<RandomAccessFile>
Unlocks the file or part of the file. [...]
unlockSync([int start = 0 int end = -1 ]) → void
Synchronously unlocks the file or part of the file. [...]
writeByte(int value) Future<RandomAccessFile>
Writes a single byte to the file. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the write completes.
writeByteSync(int value) int
Synchronously writes a single byte to the file. Returns the number of bytes successfully written. [...]
writeFrom(List<int> buffer, [ int start = 0 int end ]) Future<RandomAccessFile>
Writes from a List<int> to the file. It will read the buffer from index start to index end. If start is omitted, it'll start from index 0. If end is omitted, it will write to end of buffer. [...]
writeFromSync(List<int> buffer, [ int start = 0 int end ]) → void
Synchronously writes from a List<int> to the file. It will read the buffer from index start to index end. If start is omitted, it'll start from index 0. If end is omitted, it will write to the end of buffer. [...]
writeString(String string, { Encoding encoding: utf8 }) Future<RandomAccessFile>
Writes a string to the file using the given Encoding. Returns a Future<RandomAccessFile> that completes with this RandomAccessFile when the write completes.
writeStringSync(String string, { Encoding encoding: utf8 }) → void
Synchronously writes a single string to the file using the given Encoding. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited