简体   繁体   English

dart/flutter 中的 app_flutter 目录是什么

[英]What is app_flutter directory in dart/flutter

I'm working on a flutter application, and I want to write to a JSON file.我正在开发 flutter 应用程序,我想写入 JSON 文件。

My JSON file is in the 'assets/' folder that I created and added to pubspec.yaml.我的 JSON 文件位于我创建并添加到 pubspec.yaml 的“assets/”文件夹中。 I can get the data using:我可以使用以下方法获取数据:

final String res2 = await rootBundle.loadString("assets/profile.json");

I went through here to get the path to the file: https://docs.flutter.dev/cookbook/persistence/reading-writing-files ,我通过这里获取文件的路径: https://docs.flutter.dev/cookbook/persistence/reading-writing-files

Like this:像这样:

Future<File> get _localFile async {
  final path = await _localPath;
  return File('$path/assets/profile.json');
}

Future<String> get _localPath async {
  final directory = await getApplicationDocumentsDirectory();
  return directory.path;
}

Future<File> writeJSON(newDatas) async {
  final file = await _localFile;
  // Write the file
  return file.writeAsString('$newDatas');
}

But when I try to access the file, I get this error:但是当我尝试访问该文件时,我收到此错误:

Cannot open file, path = '/data/user/0/com.example.myapp/app_flutter/assets/profile.json'

Do you know why?你知道为什么吗?

Thank you!谢谢!

You can navigate to this path with root privileges.您可以使用 root 权限导航到此路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM