我實現了一個在外部存儲中生成和創建文件的應用程序。你們能幫我解決嗎?Android:如何從外部存儲中刪除文件?
謝謝 錢德拉
編輯-1:我添加以下代碼,還是我收到了同樣的問題,請看看我下面的代碼,
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。執行此操作後,我附加了我的屏幕截圖。請看看這個。並建議我。
如果你的文件是外部移動存儲(SD卡)內,你應該使用DocumentFile和存儲訪問架構而不是爲版本> =奇巧 – HendraWD