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..

有帮助吗?

解决方案 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

其他提示

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?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top