writeFile method

Future<void> writeFile(
  1. Object path,
  2. Object data, [
  3. WriteFileOptions? options
])

Write data to the given path, by default creating a new file if needed, else overwriting.

const encoder = new TextEncoder();
const data = encoder.encode("Hello world\n");
await Deno.writeFile("hello1.txt", data);  // overwrite "hello1.txt" or create it
await Deno.writeFile("hello2.txt", data, { create: false });  // only works if "hello2.txt" exists
await Deno.writeFile("hello3.txt", data, { mode: 0o777 });  // set permissions on new file
await Deno.writeFile("hello4.txt", data, { append: true });  // add data to the end of the file

Requires allow-write permission, and allow-read if options.create is false.

Implementation

_i2.Future<void> writeFile(
  _i2.Object path,
  _i2.Object data, [
  _i4.WriteFileOptions? options,
]) =>
    _i3.promiseToFuture(_i3.callMethod(
      this,
      'writeFile',
      [
        path,
        data,
        options ?? _i6.undefined,
      ],
    ));