Erdinc Ay Erdinc Ay - 1 year ago 113
Android Question

How to read from the internal storage (subfolder Download)?

After intensive search I could not find out how to read a configuration file (xml) from the internal storage (sub-folder download). I tried to access

but received an Exception.

When trying to get the available folders from the two possible suppliers
, I get these informations:

context.getFilesDir().getAbsolutePath(); // /data/data/

context.getDir("Download", 0).getAbsolutePath();
// /data/data/

context.getDir("Download", 1).getAbsolutePath();
// /data/data/

// /storage/emulated/0
// /storage/emulated/0/Android/data/

// /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?

Answer Source
  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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download