FileReader class
Convenience class for reading character files.
The constructors of this class assume that the default character encoding
and the default byte-buffer size are appropriate. To specify these values
yourself, construct an InputStreamReader
on a FileInputStream.
FileReader is meant for reading streams of characters. For reading streams of raw bytes, consider using FileInputStream.
Example Usage
// Reading a text file
final reader = FileReader('document.txt');
try {
final content = await reader.readAll();
print('Document content: $content');
} finally {
await reader.close();
}
// Reading line by line
final reader = FileReader('data.txt');
try {
String? line;
int lineNumber = 1;
while ((line = await reader.readLine()) != null) {
print('Line $lineNumber: $line');
lineNumber++;
}
} finally {
await reader.close();
}
Constructors
- FileReader(String fileName, {Encoding encoding = utf8})
- Creates a new FileReader, given the name of the file to read from.
- FileReader.fromFile(File file, {Encoding encoding = utf8})
- Creates a new FileReader, given the File to read from.
Properties
- encoding → Encoding
-
Returns the encoding used by this reader.
no setter
- file → File
-
Returns the File object associated with this reader.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isClosed → bool
-
Returns
true
if this reader has been closed.no setterinherited - position → int
-
Returns the current character position in the file.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
checkClosed(
) → void -
Checks if the reader is closed and throws an exception if it is.
inherited
-
close(
) → Future< void> -
Closes the stream and releases any system resources associated with it.
override
-
mark(
int readAheadLimit) → void -
Marks the present position in the stream.
inherited
-
markSupported(
) → bool -
Tells whether this stream supports the mark() operation.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
List< int> cbuf, [int offset = 0, int? length]) → Future<int> -
Reads characters into an array.
override
-
readAll(
) → Future< String> -
Reads all remaining characters from the reader.
override
-
readChar(
) → Future< int> -
Reads a single character.
override
-
readLine(
) → Future< String?> -
Reads a line of text.
override
-
ready(
) → Future< bool> -
Tells whether this stream is ready to be read.
override
-
reset(
) → Future< void> -
Resets the stream.
inherited
-
skip(
int n) → Future< int> -
Skips characters.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited