Android的 - 创建数据文件夹/数据/包装/ files目录 [英] Android - Creating a folder in the data/data/pkg/files directory

查看:484
本文介绍了Android的 - 创建数据文件夹/数据/包装/ files目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引用这样一个问题:

<一个href="http://stackoverflow.com/questions/1889188/how-to-create-files-hierarchy-in-anroids-data-data-pkg-files-directory">How在Anroids/数据/数据​​/包装/ files目录下创建文件层次?

有这个问题,使用内置的标准Java库,我该如何定位到数据/数据​​/ PKG目录,并创建文件夹和文件中有什么样的解决方案呢?也许使用一些Android的电话在可能的情况?

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.

推荐答案

的getContext()。GETDIR()方法是你的朋友

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);

这篇关于Android的 - 创建数据文件夹/数据/包装/ files目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆