uri、file、path互相转换

uri转file:

Uri uri = Uri.parse("file:"+path);
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转uri:

URI uri = file.toURI(); 

file转path:

String path = file.getPath()  

path转uri:

Uri uri = Uri.parse(path);  

path转file:

File file = new File(path)  

你可能感兴趣的:(java)