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)  



  • 2020-01-03 00:36:00

    break和continue详解for循环

    1. break:直接跳出当前循环体(while、for、do while)或程序块(switch)。其中switch case执行时,一定会先进行匹配,匹配成功返回当前case的值,再根据是否有break,判断是否继续输出,或是跳出判断(可参考switch的介绍)。 2. continue:不再执行循环体中continue语句之后的代码,直接进行下一次循环。

  • 2020-01-04 08:14:56

    input上传图片,获取图片上传尺寸

    onchange触发,获取当前file对象(这里可以获取图片的大小、类型、修改时间等) reader去读取文件 塞到页面,获取图片的宽高 移出图片节点

  • 2020-01-04 08:19:28

    flex 布局子内容p元素被撑开

    父元素 flex 布局,子元素有一行文字,将其设置为不换行隐藏后显示省略号,但实际并不是想象的那样,而导致布局变形。改怎么办?

  • 2020-01-04 18:44:26

    vue中computed源码,工作原理

    (Obeject.defineProperty是Object的一个方法,第一个参数是对象名称,第二个参数是要设置的属性名,第三个参数是一个对象,它可以设置这个属性是否可修改、可写等,而这篇文章主要使用的是Obeject.defineProperty的访问器属性,感兴趣的朋友可以自行google或者查看Js高及程序设计)