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)  



  • 2018-12-06 10:03:36

    定时杀掉processlist sleep状态的线程

    由于程序设计的Bug,导致目前这个项目使用的数据库中有很多Sleep状态的线程。找了很多解决办法,还没发现最终有效的解决方案。只能临时使用如下方法: 编写shell文件,如killSleepProcess.sh

  • 2018-12-07 08:26:37

    mysql线程池和连接池的区别

    可能有的DBA会把线程池和连接池混淆,其实两者是有很大区别的,连接池一般在客户端设置,而线程池是在DB服务器上配置;另外连接池可以取到避免了连接频繁创建和销毁,但是无法取到控制MySQL活动线程数的目标,在高并发场景下,无法取到保护DB的作用。比较好的方式是将连接池和线程池结合起来使用。 作者:飞鸿无痕 链接:https://www.jianshu.com/p/88e606eca2a5 來源:简书 简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

  • 2018-12-07 17:47:24

    linux中wc命令用法

    Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数、字数、行数,并将统计结果显示输出。

  • 2018-12-07 22:19:33

    修改 Nginx 进程最大可打开文件数(worker_processes和worker_connections)

    worker_processes:操作系统启动多少个工作进程运行Nginx。注意是工作进程,不是有多少个nginx工程。在Nginx运行的时候,会启动两种进程,一种是主进程master process;一种是工作进程worker process。例如我在配置文件中将worker_processes设置为4,启动Nginx后,使用进程查看命令观察名字叫做nginx的进程信息,我会看到如下结果: