如何从Android的内部存储(子文件夹中下载)读? (大于Android 4.0版本) [英] How to read from the INTERNAL STORAGE (subfolder DOWNLOAD) of Android? (>Android 4.0)

查看:156
本文介绍了如何从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。

我的文件,我怎么能正常访问呢?


解决方案

  1. 设置只读权限在AndroidManifest.xml中:

     <使用许可权的android:NAME =android.permission.READ_EXTERNAL_STORAG​​E/>


  2. 使用以下code:

     字符串文件名= Environment.getExternalStorageDirectory()的getPath()+文件分割符+下载+文件分割符+config.xml中。


  3. 使用文件名任何你想做的事情。

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?

解决方案

  1. Set the Read-Permission in your AndroidManifest.xml:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    

  2. Use the following code:

    String filename = Environment.getExternalStorageDirectory().getPath() + File.separator + "download" + File.separator + "config.xml";
    

  3. Use filename for whatever you want to do.

这篇关于如何从Android的内部存储(子文件夹中下载)读? (大于Android 4.0版本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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