Skip to content
Justice Tech School

Dart Files

dart:io offers File with readAsString, writeAsString and exists. Most methods return Futures, so use async and await.

Example
import 'dart:io';
Future<void> main() async {
  var f = File("demo.txt");
  await f.writeAsString("one\n");
  print(await f.readAsString());
  await f.delete();
}

Exercise

Read all text.

await f.()

Quiz Test

What do file methods return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.