uri,file,path互相转化

2017-12-24 11:43:48

uri转file:


[html] view plain copy print?

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


uri转path:



[html] view plain copy print?

  1. private String getPath(Uri uri) {  

  2.        String[] projection = {MediaStore.Video.Media.DATA};  

  3.        Cursor cursor = managedQuery(uri, projection, null, null, null);  

  4.        int column_index = cursor  

  5.                .getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);  

  6.        cursor.moveToFirst();  

  7.        return cursor.getString(column_index);  

  8.    }  




file转uri:


[html] view plain copy print?

  1. URI uri = file.toURI();  



file转path:


[html] view plain copy print?

  1. String path = file.getPath()  





path转uri:


[html] view plain copy print?

  1. Uri uri = Uri.parse(path);  


path转file:



[html] view plain copy print?

  1. File file = new File(path)  



  • 2017-11-19 00:17:51

    Java如何获取Date的“昨天”与“明天”示例代码

    最近在做项目的时候用到Date和Calendar比较多,而且用到的方式也比较全,突然想到一个问题,Java如何获取Date的"昨天"与"明天",也就是前一天和后一天呢?思考后写出了方法,想着万一以后用到,就总结出来,也方便有需要的朋友们参考借鉴,下面来一起看看吧。

  • 2017-11-23 02:00:51

    js 分页插件twbs-pagination

    ​cdn地址 http://www.bootcdn.cn/twbs-pagination/ 官网地址 可以在cdn地址上面查看到