OLD | NEW |
---|---|
(Empty) | |
1 import 'dart:io'; | |
2 import 'dart:async'; | |
3 | |
4 void printDailyNewsDigest() { | |
5 File file = new File('dailyNewsDigest.txt'); | |
6 file.readAsString() // readAsString() returns a Future. | |
7 .then((content) { // Specifies what to do if the Future completes successf ully. | |
8 print(content); // Executes when the file has been successfully read. | |
9 }) | |
10 .catchError((error) { // Specifies error handling code. | |
11 print("Sorry, no news today. Here's why:\n"); | |
12 print('$error'); | |
13 }); | |
14 } | |
15 | |
16 main() { | |
17 printDailyNewsDigest(); | |
18 } | |
OLD | NEW |