Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Last active November 21, 2018 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphicbeacon/2f4656ae3528fbdefd180d50471f4490 to your computer and use it in GitHub Desktop.
Save graphicbeacon/2f4656ae3528fbdefd180d50471f4490 to your computer and use it in GitHub Desktop.
Learn Dart #5: Read and write files in under 30 seconds
import 'dart:io';
main() async {
var file = File('data.txt');
var contents;
if (await file.exists()) {
// Read file
contents = await file.readAsString();
print(contents);
// Write file
var fileCopy = await File('data-copy.txt').writeAsString(contents);
print(await fileCopy.exists());
print(await fileCopy.length());
}
}
@graphicbeacon
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment