write private file to internal storage

大兔子大兔子 提交于 2019-12-23 17:38:35

问题


I trying to write some files on the internal storage.

I saw theFileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); on Data Storage and I understood that the file will be private to my application.

but the problem is it can only open a file without a path, so first I opened a new directory file with file.mkdir(), but now, how do I write the file as private ?


回答1:


I saw theFileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); on Data Storage and I understood that the file will be private to my application.

Correct. They will be private by default.

but the problem is it can only open a file without a path, so first I opened a new directory file with file.mkdir(), but now, how do I write the file as private ?

Your files that you create in subdirectories off of in getFilesDir() are private by default -- you do not have to do anything special to make them be private.




回答2:


If you call Context.openFileOutput() the file will always be written into your application's data directory (i.e. "/data/data/appname/filename"). You cannot use sub folders here! The documentation for this function says

nameThe name of the file to open; can not contain path separators.



来源:https://stackoverflow.com/questions/6773497/write-private-file-to-internal-storage

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