我正在实现一个在外部存储中生成和创建文件的应用程序。我该如何删除?
编辑
我添加了以下代码,但仍然遇到相同的问题。请参阅下面的代码:

String fullPath = "/mnt/sdcard/";
System.out.println(fullPath);
try{
    File file = new File(fullPath, "audio.mp3");
    if(file.exists()){
        boolean result = file.delete();
        System.out.println("Application able to delete the file and result is: " + result);
        // file.delete();
    }else{
        System.out.println("Application doesn't able to delete the file");
    }
}catch (Exception e){
    Log.e("App", "Exception while deleting file " + e.getMessage());
}
在LogCat中,我正在获取应用程序,该应用程序能够删除该文件,并且结果是:false 。执行此操作后,我附上了我的屏幕截图。

最佳答案

File file = new File(selectedFilePath);
boolean deleted = file.delete();

其中selectedFilePath是要删除的文件的路径,例如:
/sdcard/YourCustomDirectory/ExampleFile.mp3

关于Android:如何从外部存储中删除文件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14727226/

10-11 22:43
查看更多