各位 Dart 程序员。
我正在使用 Stream 读取文件,如下所示。
Stream<List<int>> stream = new File(filepath).openRead();
stream
.transform(UTF8.decoder)
.transform(const LineSpilitter())
.listen((line){
// TODO: check if this is the last line of the file
var isLastLine;
});
Run Code Online (Sandbox Code Playgroud)
我想检查listen()中的行是否是文件的最后一行。
我认为您无法检查当前数据块是否是最后一个。
您只能传递关闭流时调用的回调。
Stream<List<int>> stream = new File('main.dart').openRead();
stream.
.transform(UTF8.decoder)
.transform(const LineSpilitter())
.listen((line) {
// TODO: check if this is the last line of the file
var isLastLine;
}
,onDone: (x) => print('done')); // <= add a second callback
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3359 次 |
| 最近记录: |