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
Properties
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< List< int> > -
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 intobuffer
from at indexstart
, otherwise index 0. Ifend
is present, theend
-start
bytes will be read intobuffer
, otherwise up tobuffer.length
. Ifend
==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 intobuffer
from at indexstart
, otherwise index 0. Ifend
is present, theend
-start
bytes will be read intobuffer
, otherwise up tobuffer.length
. Ifend
==start
nothing happens. [...] -
readSync(
int bytes) → List< int> -
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 aFuture<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 indexend
. Ifstart
is omitted, it'll start from index 0. Ifend
is omitted, it will write to end ofbuffer
. [...] -
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 indexend
. Ifstart
is omitted, it'll start from index 0. Ifend
is omitted, it will write to the end ofbuffer
. [...] -
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