Android, delete files in my data directory?

自作多情 提交于 2019-12-02 02:39:04

问题


My application stores some files that are required for it to run in the data directory of the app

/data/data/com.example.myapp/files/filehere.file

When my application is updated from the market, it is important that I clear the files in the data directory, and update them to the latest ones from the new package that has just been downloaded.

My question is, how do I programatically delete the files in the directory in question?

Alternatively, is there an alternative directory that I can store the files in that are persistent across the lifetime of my application version, but will be cleared once an update is installed?


回答1:


File file = new File(FILEPATH);
if(file.exists())
  file.delete();

As for your last question, my guess is you'll have to control that on your upgrade process. f.e., create a directory for each version and manage the files inside when the user upgrades.




回答2:


You might be better off using a database wrapped in SQLiteOpenHelper. You can then use the onUpgrade function to detect a new app version.



来源:https://stackoverflow.com/questions/5637835/android-delete-files-in-my-data-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!