【发布时间】: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;
}
}
如何阅读内容?
感谢您的帮助
【问题讨论】: