File,URI,path互转
Android
URI
Uri=>file
file = new File(new URI(uri.toString()));
uri=>path
private String getPath(Uri uri) {
String[] projection = {MediaStore.Video.Media.DATA};
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
File
file=>uri
URI uri = file.toURI();
file=>path
String path = file.getPath();
PATH
path=>uri
Uri uri = Uri.parse(path);
path=>file
File file = new File(path);