Question

I want to search a file in mobile which may present in SDcard or else where.After finding the file i should delete the file.Both process like searching and deletion should be done in back ground without knowing the user .How to implement this can any one help me..

Était-ce utile?

La solution 2

Fist you have to find the file. Start in root directory, list all entries and compare them with your pattern. If not found, go into each of the listed directories and repeat the process. Keywords: depth first search, recurrency.

You can delete the file using File.delete method. As simple as that. Also, you will need WRITE_EXTERNAL_STORAGE permission.

See: http://developer.android.com/reference/java/io/File.html

Autres conseils

for searching the file named "b.html" in folder named "a"...

File extStore = Environment.getExternalStorageDirectory();
File myFile = new File(extStore.getAbsolutePath() + "/a/b.html");

if(myFile.exists()){
    ...
}

and for deleting the file, see this...

How to delete a file from SD card?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top