June 2017
Intermediate to advanced
873 pages
18h 9m
English
In this recipe, we demonstrate the three most important ways to write to a file. You can find the code in the project writing_files.
The three ways to write to a file are discussed as follows:
io and convert as shown in the following code:import 'dart:io';
import 'dart:convert';
void main() {writeAsString as shown in the following code: final filename = 'outString.txt';
new File(filename).writeAsString('Dart is an elegant language').then((File file) {
// do something with the file.
});writeAsBytes as shown in the following code: final string = '你好世界';
// Encode to UTF8.
var encodedData = UTF8.encode(string);
new File('outUTF8.txt').writeAsBytes(encodedData).then((file) ...Read now
Unlock full access