I am making an app in which I have to delete the recently added mp3 file in sdcard. The format in which the song is saved is:
Songhello_17_26.amr
where 17_26 is the time when song was added. Can anyone help me how delete the recently added file in sdcard. I mean to say that I want to delete the time means the latest added file should get deleted. Any help will be appreciated.
As it states here, you cant do that directly, you first need to get list of files
File.listFiles()
,Comparator
,File.lastModified()
,Arrays.sort()
and delete.Edited:
To delete latest one:
try this too:
that code you can see the latest file saved in sdcard, i suggest you to follow along this tutorial.
**try this method :
or you can use the following code to delete the file from sd-card:
File folder = Environment.getExternalStorageDirectory(); String fileName = folder.getPath() + "/pass/hello.pdf";
withTry this