我在 Flutter 中写入文件时遇到问题。我不断收到此错误:
FileSystemException: Cannot create file, path = '/data/local/tmp/temp.png' (OS Error: Permission denied, errno = 13)
出于某种原因,它只发生在某些设备上。我自己似乎无法复制这个问题,但是人们向我报告了它。
这是基本代码:
final Io.Directory systemTempDir = Io.Directory.systemTemp;
final Io.File file = await new Io.File('${systemTempDir.path}/temp.png').create();
file.writeAsBytes(finalImage);
Run Code Online (Sandbox Code Playgroud)
小智 9
在 Android Q 中,只需在 AndroidManifest 文件中添加以下几行:
<application
android:requestLegacyExternalStorage="true"
Run Code Online (Sandbox Code Playgroud)
根据所使用的设备,路径可能存在问题。看看 path_provider 插件:https ://pub.dartlang.org/packages/path_provider
在 flutter.io 上的 Flutter Cookbook 中有一篇关于如何读写文件的好文章:https ://flutter.io/cookbook/persistence/reading-writing-files/
| 归档时间: |
|
| 查看次数: |
14934 次 |
| 最近记录: |