如何在Flutter中从本地存储中删除文件?

穆罕默德·塔姆·拉斐(Muhammad Tameem Rafay)

其实我想覆盖手机本地存储中的文件,但这给了我错误

    I/flutter ( 3835): /storage/emulated/0/Android/data/com.example.temp/files/flutter_audio_recorder_
I/flutter ( 3835): Exception: A file already exists at the path :/storage/emulated/0/Android/data/com.example.temp/files/flutter_audio_recorder_.wav

所以我该如何先删除该文件?

我已经将wav文件路径存储在此变量==> var dirPath中;

公路警察
Future<void> deleteFile() async {
  try {
    var file = File('your_file_path');

    if (await file.exists()) {
      // file exits, it is safe to call delete on it
      await file.delete();
    }

  } catch (e) {
    // error in getting access to the file
  }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章