14.Dart - File文件

Dart - File文件

File读取和读取后输出

import 'dart:io';

void main() {
  //then方法:可以得到Future的结果并且能够返回一个新的Future

  new File(r"C:\Users\zhulianghao\Desktop\Dart异步编程.md")
      .readAsString() //读取文件,提交任务
      .then((s) {
    //接受任务
    print(s);
    return 1;
  }).then((msg) {
    print(msg);
  }).catchError((e, s) {
    print(e.runtimeType);
    print(e);
    print(s.runtimeType);
    print(s);
  });

  Future.forEach([1, 2, 3, 4], (i) {
    print(i);
  });

  //

  Future.wait([
    Future.delayed(Duration(seconds: 1)),
    Future.delayed(Duration(seconds: 2))
  ]).then((_) {
    print(1);
  });
}
发布了49 篇原创文章 · 获赞 6 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/zlhyy666666/article/details/104625960