Delete file from internal storage

前端 未结 8 1656
借酒劲吻你
借酒劲吻你 2020-11-30 00:28

I\'m trying to delete images stored in internal storage. I\'ve come up with this so far:

File dir = getFilesDir();
File file = new File(dir, id+\".jpg\");
bo         


        
8条回答
  •  猫巷女王i
    2020-11-30 00:49

    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)
    

提交回复
热议问题