在Android上获取绝对路径 [英] Getting absolute path on android
问题描述
我有c ++代码,其中尝试从android设备上的目录中获取文件.我尝试了不同的方法来设置传递给fopen()函数的路径,例如: /Android/data/com.myapp/files/Blip.wav 实际上有这个文件.但是我想这不是编写路径的正确方法. (该示例是通过Java代码获得的)
I've got c++ code in which I try to get a file from a directory on an android device. I've tried different ways to set the path which I pass to the fopen() function like: /Android/data/com.myapp/files/Blip.wav There actually is this file. But I guess that this is not a proper way to write a path. (The example was obtained by the java code )
getContext().getApplicationContext().getFilesDir().getPath() + "/Blip.wav"
推荐答案
实际上有这个文件
There actually is this file
由于我从未见过具有/Android
目录的Android设备,因此不太可能.
Since I have never seen an Android device with an /Android
directory, that is unlikely.
如果您正在使用USB或类似连接在台式机文件管理器中查看/Android/data/com.myapp/files/Blip.wav
,那么将适合什么.在这种情况下,Android/data/com.myapp/files/Blip.wav
是外部存储中的相对路径.具体来说,它映射到:
What would fit is if you are looking at /Android/data/com.myapp/files/Blip.wav
in a desktop file manager, using a USB or similar connection. In that case, Android/data/com.myapp/files/Blip.wav
is a relative path in external storage. Specifically, it maps to:
new File(getContext().getExternalFilesDir(), "Blip.wav")
这篇关于在Android上获取绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!