readFile method

Future<Uint8List> readFile(
  1. Object path, [
  2. ReadFileOptions? options
])

Reads and resolves to the entire contents of a file as an array of bytes. TextDecoder can be used to transform the bytes to string if required. Reading a directory returns an empty data array.

const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile("hello.txt");
console.log(decoder.decode(data));

Requires allow-read permission.

Implementation

_i2.Future<_i9.Uint8List> readFile(
  _i2.Object path, [
  _i4.ReadFileOptions? options,
]) =>
    _i3.promiseToFuture(_i3.callMethod(
      this,
      'readFile',
      [
        path,
        options ?? _i6.undefined,
      ],
    ));