Android - Creating a folder in the data/data/pkg/files directory

女生的网名这么多〃 提交于 2019-12-18 13:23:04

问题


Referencing this question:

How to create files hierarchy in Androids '/data/data/pkg/files' directory?

What kind of a solution is there to this problem using the built in standard Java libraries, how do I navigate to the data/data/pkg directory and create folders and files in there? Maybe using some of the Android calls where possible?

When a user uses my app I wish to save any files associated with that user in a folder pkg/files/username, so that I can easily read these folders later. My other option is include the username in the filename but this isn't a very suitable and clean method in my opinion.


回答1:


getContext().getDir() method is your friend

File dir = ctx.getDir("my_sub_dir", Context.MODE_PRIVATE);
File newfile = new File(topDirFile.getAbsolutePath() + File.separator + "new_file_name");
newfile.createNewFile();
BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(newfile), 16 * 1024);


来源:https://stackoverflow.com/questions/5486623/android-creating-a-folder-in-the-data-data-pkg-files-directory

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