我正在尝试写入存储在android Studio资产中的现有txt文件。但是,它会引发错误
assets:
- assets/responseFile.txt
这是我的代码:
String content = response.body.toString();
String path = "assets/responseFile.txt";
var file = new File(path);
file.writeAsString(content);
我也尝试过这种方式。但是没有运气
writingFile(String content) async {
Directory appDocDir = await getApplicationDocumentsDirectory();
String filePath = '${appDocDir.path}/assets/responseFile.txt';
new File(filePath).writeAsString(content);}
答案 0 :(得分:0)
您的pubspec.yaml错误。应该是:
flutter:
assets:
- assets/responseFile.txt #This in case the file is stored in the "assets" folder on the root of your Flutter project.
此外,您必须确保尊重标识。