我的应用程序从服务器下载文件并将其存储在:
/mnt/sdcard/Android/data/com.test/files
。 (/mnt/sdcard 派生自 Environment.getExternalStorageDirectory();
)
每次我将应用程序从 eclipse(运行菜单)重新部署到模拟器时,它都会删除该文件。
未选中运行配置中的复选框“目标/删除用户数据”。
我正确地关闭了所有 BufferedOutputStreams
,所以我认为这不是我的应用程序本身。
我是否使用了正确的目录来存储持久数据? (我的文件大约有 70-100M)
有什么提示吗?
最佳答案
来自getExternalStorageDirectory's doc :
Applications should not directly use this top-level directory, in order to avoid polluting the user's root namespace. Any files that are private to the application should be placed in a directory returned by Context.getExternalFilesDir, which the system will take care of deleting if the application is uninstalled. Other shared files should be placed in one of the directories returned by getExternalStoragePublicDirectory(String).
您的 /mnt/sdcard/Android/data/com.test/files
应该在您的 Context.getExternalFilesDir()
中,当应用程序卸载时它会被删除.
关于android emulator/eclipse 在重新部署时删除应用程序文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3694055/