获取/data/data/my.app/files路径编程? [英] Getting /data/data/my.app/files path programmatically?
问题描述
在我的应用程序,我刚刚成功下载一个文件,我打开了它是这样的:
In my app, I've just successfully downloaded a file and I opened it like this:
OutputStream output = openFileOutput("myfile.txt", Context.MODE_PRIVATE);
随着一点点的浏览,我发现我的文件中的 /data/data/my.app.namespace/files/myfile.txt
。我不想硬code中的路径,但后来在我的应用我将要访问的myfile.txt,我要动态地获取文件夹路径。我试过最喜欢 Environment.getDataDirectory()在
但只返回环保
对象中的文件夹。getAbsolutePath() /数据
。我在哪里可以期待,以到达私人文件去了?或者是安全的假设,这个结构会不会改变?我不喜欢硬编码,但它会工作......
With a little browsing, I've found my file in /data/data/my.app.namespace/files/myfile.txt
. I don't want to hardcode the path but later on in my app I'm going to want to access myfile.txt and I want to dynamically get that folder path. I've tried most of the folders in the Environment
object like Environment.getDataDirectory().getAbsolutePath()
but that only returns /data
. Where can I look to get where private files go? Or is it safe to assume that this structure won't change? I don't like hardcoding it, but it would work...
推荐答案
您可以用做 context.getFilesDir()+/filename.ext\"$c$c>
这篇关于获取/data/data/my.app/files路径编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!