如何从Dart VM程序“读取”文件? [英] How does one 'read' a file from a Dart VM program?

查看:120
本文介绍了如何从Dart VM程序“读取”文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Dart程序中读取文件?

How does one 'read' a file from a Dart program ?

http://api.dartlang.org/index.html

Dart会在客户端运行,因此文件作为输入。

Dart would be running on the client-side and so taking files as input should be allowed.

推荐答案

您可以在Dart的测试框架中找到文件的使用:
status_file_parser.dart (搜索File)。

You can find a usage of files in Dart's testing framework: status_file_parser.dart (search for 'File').

简而言之:

  File file = new File(path);
  if (!file.existsSync()) <handle missing file>;
  InputStream file_stream = file.openInputStream();
  StringInputStream lines = new StringInputStream(file_stream);

  lines.lineHandler = () {
    String line;
    while ((line = lines.readLine()) != null) {
    ...
  };
  lines.closeHandler = () {
    ...
  };

请注意,API尚未完成,可能随时发生变化。

Note that the API is not yet finalized and could change at any moment.

编辑:API已更改。请参见新IO概述

API has changed. See Introduction to new IO

这篇关于如何从Dart VM程序“读取”文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆