gpt4 book ai didi

android - 如何使用 flutter "File Class"删除 android 上的文件?

转载 作者:IT王子 更新时间:2023-10-29 07:07:13 26 4
gpt4 key购买 nike

<分区>

我正在制作一个 flutter 应用程序,我想让用户能够使用我的应用程序从 SD 卡或手机存储中删除文件。使用代码

File f = new File.fromUri(Uri.file(song.uri));
f.delete();

File Class 中有两个函数 delete()deleteSync() 我尝试使用这两个函数但是出现错误与 permission denied 相关。那我怎么删除文件呢??

删除文件时出错--

E/flutter (16195): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (16195): FileSystemException: Cannot delete file,
path = '/storage/2748-0816/Music/AUD-20180613-WA0006.mp3' (OS Error: Permission denied, errno = 13)
E/flutter (16195): #0 _File._delete.<anonymous closure> (dart:io/file_impl.dart:295:9)
E/flutter (16195): #1 _RootZone.runUnary (dart:async/zone.dart:1381:54)
E/flutter (16195): #2 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
E/flutter (16195): #3 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633:45)
E/flutter (16195): #4 Future._propagateToListeners (dart:async/future_impl.dart:662:32)
E/flutter (16195): #5 Future._completeWithValue (dart:async/future_impl.dart:477:5)
E/flutter (16195): #6 Future._asyncComplete.<anonymous
closure> (dart:async/future_impl.dart:507:7)
E/flutter (16195): #7 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (16195): #8 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

我的android xml文件

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com