Delete file from internal storage Delete file from internal storage android android

Delete file from internal storage


The getFilesDir() somehow didn't work.Using a method, which returns the entire path and filename gave the desired result. Here is the code:

File file = new File(inputHandle.getImgPath(id));boolean deleted = file.delete();


This works for me:

Java

File file = new File(photoPath);file.delete();MediaScannerConnection.scanFile(context,                new String[]{file.toString()},                new String[]{file.getName()},null);

Kotlin

val file = File(photoPath) file.delete()MediaScannerConnection.scanFile(context, arrayOf(file.toString()),      arrayOf(file.getName()), null)