在Dart中读取文件

时间:2012-05-05 11:04:51

标签: dart dart-html dart-io

我正在尝试使用Dartium浏览器上的Dart从机器读取文件(在我的桌面上为此目的制作一个简单的.txt文件)。

我有一个输入字段,添加了一个监听器,它的外观如下:

  void _onFileSelect(event) {
    dom.File file = _fileInput.files.item(0);

    dom.FileReader reader = new dom.FileReader();
    //reader.readAsBinaryString(file);

    reader.addEventListener('load', (event) {
      print(reader.result); // This is the line I am having the problem with.
    });

    reader.readAsText(file);
  }

当我选择文件时,我收到错误:

  

Stack Trace:0。功能:'Object.noSuchMethod'url:'bootstrap'行:717 col:3

在我使用内联注释标记的行上。

我还设置了一个脚本来执行带有所需标志的Dartium:

#!/bin/sh
cd /opt/DartEditor/dart-sdk/chromium
./chrome.exe --allow-file-access-from-files $@

任何人都可以提出问题所在的提示吗?

P.S。我使用的是Ubuntu Precise x64。

1 个答案:

答案 0 :(得分:3)

抱歉,您无法在Dartium中使用dart:io库。这些库仅在命令行上使用Dart VM。

您可能希望使用XMLHttpRequest从HTTP服务器读取文件。