【问题标题】:cannot parse a file in flutter/dart无法解析颤振/飞镖中的文件
【发布时间】:2019-10-21 13:08:45
【问题描述】:

需要一些帮助来获取文件内容。

我使用颤振文件选择器插件来获取文件。插件返回路径。

'/Users//Library/Developer/CoreSimulator/Devices/A509517C-AC3F-4F87-856A-145F61075E8B/data/Containers/Data/Application/FC2B634B-F7BD-48EB-9B80-920476E20DE8/tmp/com.xyx-收件箱/myfile.doc'

当我试图阅读 Dart 中的内容时,我得到了错误

flutter:FileSystemException:无法使用编码“utf-8”解码数据

这是我的代码

Future<int> readFileStream(String path) async {
    print(path);
    File file = await new File(path);
    file.length().then((len) {
      print(len);
    });
    try {
      // Read the file
      String contents = await file.readAsString();
      return int.parse(contents);
    } catch (e) {
      print(e);
      // If encountering an error, return 0
      return 0;
    }
  }

如何阅读内容?

感谢您的帮助

【问题讨论】:

标签: flutter dart


【解决方案1】:

我的猜测是它是一个二进制的word文档,所以你应该把它读成字节而不是字符串。

【讨论】:

    猜你喜欢
    • 2023-03-05
    • 2020-09-12
    • 2020-05-19
    • 2021-03-06
    • 1970-01-01
    • 2019-01-07
    • 2020-04-04
    • 2019-06-26
    • 2020-08-12
    相关资源
    最近更新 更多