该方法 readAsString()
用一个字符串返回整个内容。
例如,这里是一个源文件。
#line1 // note, the carriage return here (new line symbol)
#line2
如何像源文件那样用行来区分内容,即用行来区分内容?
await file.readAsString().then(
(value) {
print(value); // the whole content will be printed
// how to iterate the content by lines
// i.e. process at first `#line1` and so on
},
);
使用 File.readAsLines
:
await file.readAsLines().then(
(List<String> lines) {
for (var line in lines) {
...
}
},
);