如何从Android的内部存储(子文件夹中下载)读? (大于Android 4.0版本) [英] How to read from the INTERNAL STORAGE (subfolder DOWNLOAD) of Android? (>Android 4.0)
问题描述
在强化搜索我无法找出如何读取内部存储(子文件夹中下载)一个配置文件(XML)。我试图访问的 /mnt/sdcard/Download/config.xml 的却收到一个例外。
当试图从两个可能的供货商那里得到的可用文件夹的的ApplicationContext 和环保,我得到这些信息:
context.getFilesDir()。getAbsolutePath()
/data/data/com.xxx.yyy/filescontext.getDir(下载,0).getAbsolutePath()
/data/data/com.xxx.yyy/app_Downloadcontext.getDir(下载,1).getAbsolutePath()
/data/data/com.xxx.yyy/app_DownloadEnvironment.getExternalStorageDirectory()。getAbsolutePath()
/存储/模拟/ 0context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()
/storage/emulated/0/Android/data/com.xxx.yyy/files/DownloadEnvironment.getDataDirectory()的getPath()
/数据
当我尝试这些信息来访问的 config.xml中在下载 -folder(我手动复制Windows资源管理器的文件),我收到错误,如FileNotFoundException异常或者抛出IllegalArgumentException。
我的文件,我怎么能正常访问呢?
-
设置只读权限在AndroidManifest.xml中:
<使用许可权的android:NAME =android.permission.READ_EXTERNAL_STORAGE/>
-
使用以下code:
字符串文件名= Environment.getExternalStorageDirectory()的getPath()+文件分割符+下载+文件分割符+config.xml中。
- 使用
文件名
任何你想做的事情。
After intensive search I could not find out how to read a configuration file (xml) from the internal storage (subfolder download). I tried to access /mnt/sdcard/Download/config.xml but received an Exception.
When trying to get the available folders from the two possible suppliers ApplicationContext and Environment, I get these informations:
context.getFilesDir().getAbsolutePath()
/data/data/com.xxx.yyy/files
context.getDir("Download", 0).getAbsolutePath()
/data/data/com.xxx.yyy/app_Download
context.getDir("Download", 1).getAbsolutePath()
/data/data/com.xxx.yyy/app_Download
Environment.getExternalStorageDirectory().getAbsolutePath()
/storage/emulated/0
context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()
/storage/emulated/0/Android/data/com.xxx.yyy/files/Download
Environment.getDataDirectory().getPath()
/data
When I try these information to access the config.xml in the Download-folder (I manually copied the file over the Windows explorer) I receive errors, e.g. FileNotFoundException or IllegalArgumentException.
Where is my file, and how can I access it properly?
Set the Read-Permission in your AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Use the following code:
String filename = Environment.getExternalStorageDirectory().getPath() + File.separator + "download" + File.separator + "config.xml";
- Use
filename
for whatever you want to do.
这篇关于如何从Android的内部存储(子文件夹中下载)读? (大于Android 4.0版本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!