【发布时间】:2021-11-24 17:58:16
【问题描述】:
我正在尝试在我的颤振中读取 XML 文件。但是每次我尝试读取文件时,它只会抛出一个错误。
这是我读取 xml 文件的地方(我的 XML 文件很大)。
convertXMLtoJSON() async {
File file = File('assets/xml_file/belovedskincare.xml');
Future<String> xml = file.readAsString();
}
当我运行它时,它会抛出这个错误。
E/flutter (13956): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Cannot open file, path = 'assets/xml_file/belovedskincare.xml' (OS Error: No such file or directory, errno = 2)
我也尝试了其他一些功能,例如
file.readAsLines();
file.readAsStringSync();
但什么都没有改变。
这是我的 pubspec.yaml
资产运行良好。您可以在第二张图片中看到左侧的文件结构。
我也尝试过rootbundle,但效果不佳。
convertXMLtoJSON() async {
String file = await rootBundle.loadString('assets/xml_file/belovedskincare.xml');
print(file);
}
当我运行这个时,它显示了这个错误。
E/flutter (13956): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Null check operator used on a null value
【问题讨论】: