处理读取文件时的错误信息

1490次阅读  |  发布于5年以前

处理读取文件时的错误信息

import 'dart:io';

main() async {
  final filename = 'non_existent_file.txt';
  try {
    var file = await new File(filename).readAsString();
    print(file);
  } catch (e) {
    print('There was a ${e.runtimeType} error');
    print('Could not read $filename');
  }
}

Copyright© 2013-2019

京ICP备2023019179号-2