FileSystemException:尝试写入新文件时无法打开文件
我正在尝试使用自定义名称编写文件,但是要遇到错误,但是如果我使用常数名称,则可以正常工作,
这是我的代码
Future downloadFile(String url, String name) async {
//creating path
final tempDir =
(await AndroidExternalStorage.getExternalStoragePublicDirectory(
DirType.downloadDirectory));
//filename genearted from
customname = generated;
final file = File('$tempDir/myfolder/$customname');
try {
final response = await Dio().get(url,
onReceiveProgress: (count, total) {
setState(() {
isDownloading = true;
progress = ((count / total) * 100);
if (progress == 100) {
isDownloaded = true;
}
});
},
options:
Options(responseType: ResponseType.bytes, receiveTimeout: 0));
var raf = file.openSync(mode: FileMode.write);
raf.writeByteSync(response.data);
await raf.close();
} catch (e) {
log(e.toString());
}
}
错误日志
[log] FileSystemException: Cannot open file, path = '/storage/emulated/0/Download/myfolder/dunkin.zip' (OS Error: Permission denied, errno = 13)
I'm trying to write file with custom name but getting error but if i used constant name it works just fine
here is my code
Future downloadFile(String url, String name) async {
//creating path
final tempDir =
(await AndroidExternalStorage.getExternalStoragePublicDirectory(
DirType.downloadDirectory));
//filename genearted from
customname = generated;
final file = File('$tempDir/myfolder/$customname');
try {
final response = await Dio().get(url,
onReceiveProgress: (count, total) {
setState(() {
isDownloading = true;
progress = ((count / total) * 100);
if (progress == 100) {
isDownloaded = true;
}
});
},
options:
Options(responseType: ResponseType.bytes, receiveTimeout: 0));
var raf = file.openSync(mode: FileMode.write);
raf.writeByteSync(response.data);
await raf.close();
} catch (e) {
log(e.toString());
}
}
error log
[log] FileSystemException: Cannot open file, path = '/storage/emulated/0/Download/myfolder/dunkin.zip' (OS Error: Permission denied, errno = 13)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论