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

时间:2020-05-10 11:13:37

标签: flutter flutter-dependencies

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

    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中;

1 个答案:

答案 0 :(得分:5)

JSONObject jsonObject = new JSONObject(contents.trim());
Iterator<String> keys = jsonObject.keys();

while(keys.hasNext()) {
    String key = keys.next();
    if (jsonObject.get(key) instanceof JSONObject) {
          // do something with jsonObject here      
    }
}