RandomAccessFile class - dart:io library (original) (raw)

Random access to the data in a file.

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

A RandomAccessFile has both asynchronous and synchronous methods. The asynchronous methods all return a Futurewhereas 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 RandomAccessFileinstance at the time. If another 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.

Properties

hashCodeint

The hash code for this object.

no setterinherited

pathString

The path of the file underlying this random access file.

no setter

runtimeTypeType

A representation of the runtime type of the object.

no setterinherited

Methods

close()→ Future<void>

Closes the file.

closeSync()→ void

Synchronously closes the file.

flush()→ Future<RandomAccessFile>

Flushes the contents of the file to disk.

flushSync()→ void

Synchronously flushes the contents of the file to disk.

length()→ Future<int>

Gets the length of the file.

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.

noSuchMethod(Invocation invocation)→ dynamic

Invoked when a nonexistent method or property is accessed.

inherited

position()→ Future<int>

Gets the current byte position in the file.

positionSync()→ int

Synchronously gets the current byte position in the file.

read(int count)→ Future<Uint8List>

Reads up to count bytes from a file.

readByte()→ Future<int>

Reads a byte from the file.

readByteSync()→ int

Synchronously reads a single byte from the file.

readInto(List<int> buffer, [int start = 0, int? end])→ Future<int>

Reads bytes into an existing buffer.

readIntoSync(List<int> buffer, [int start = 0, int? end])→ int

Synchronously reads into an existing buffer.

readSync(int count)→ Uint8List

Synchronously reads up to count bytes from a file

setPosition(int position)→ Future<RandomAccessFile>

Sets the byte position in the file.

setPositionSync(int position)→ void

Synchronously sets the byte position in the file.

toString()→ String

Returns a human-readable string for this random access file.

override

truncate(int length)→ Future<RandomAccessFile>

Truncates (or extends) the file to length bytes.

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.

writeByteSync(int value)→ int

Synchronously writes a single byte to the file.

writeFrom(List<int> buffer, [int start = 0, int? end])→ Future<RandomAccessFile>

Writes from a buffer to the file.

writeFromSync(List<int> buffer, [int start = 0, int? end])→ void

Synchronously writes from a buffer to the file.

writeString(String string, {Encoding encoding = utf8})→ Future<RandomAccessFile>

Writes a string to the file using the given Encoding.

writeStringSync(String string, {Encoding encoding = utf8})→ void

Synchronously writes a single string to the file using the givenEncoding.

Operators

operator ==(Object other)→ bool

The equality operator.

inherited