Android 操作文件流技术-Uri, File ,Sting path 三者互相转化

版权声明:本文为博主csdn_aiyang原创文章,未经博主允许不得转载。 https://blog.csdn.net/csdn_aiyang/article/details/77931048

所属来源:

Uri  :  importandroid.net.Uri
File:importjava.io.File;

path:String 类型字符串地址;


一、Uri

uri 转  file:

URI fUri =new URI(uri.toString())
File file = new File(fUri); 


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)


展开阅读全文

没有更多推荐了,返回首页