How to change Uri to File on Android

Asked 2 years ago, Updated 2 years ago, 120 views

What is the easiest way to convert android.net.Uri to File?

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());

I tried it like this, but it didn't work.

file android uri file-uri

2022-09-22 15:36

1 Answers

new File(uri.getPath()); This or new File(uri.toString()); You can do it in this way.


2022-09-22 15:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.