hpique hpique - 1 year ago 381
Android Question

Convert file: Uri to File in Android

What's the easiest way to convert from a

to a
in Android?

Tried the following but it doesn't work:

final File file = new File(Environment.getExternalStorageDirectory(), "read.me");
Uri uri = Uri.fromFile(file);
File auxFile = new File(uri.toString());
assertEquals(file.getAbsolutePath(), auxFile.getAbsolutePath());

Answer Source

What you want is...

new File(uri.getPath());

... and not...

new File(uri.toString());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download