Android - 在data/data/pkg/files目录中创建一个文件夹

Tim*_*Tim 7 android file create-directory

参考这个问题:

如何在Androids'/ data/data/pkg/files'目录中创建文件层次结构?

使用内置的标准Java库有什么样的解决方案可以解决这个问题,如何导航到data/data/pkg目录并在那里创建文件夹和文件?也许在可能的情况下使用一些Android调用?

当用户使用我的应用程序时,我希望将与该用户关联的所有文件保存在文件夹pkg/files/username中,以便稍后我可以轻松阅读这些文件夹.我的另一个选择是在文件名中包含用户名,但在我看来,这不是一个非常合适和干净的方法.

ref*_*log 18

getContext().getDir()方法是你的朋友

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);
Run Code Online (Sandbox Code Playgroud)