转换文件:URI在Android文件 [英] Convert file: Uri to File in Android

查看:137
本文介绍了转换文件:URI在Android文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是从文件转换成最简单的方法: android.net.Uri 文件在Android的?

试过以下,但它不工作:

 最后文件的文件=新的文件(Environment.getExternalStorageDirectory(),read.me);
 开放的我们的uri = Uri.fromFile(文件);
 文件auxFile =新的文件(uri.toString());
 的assertEquals(file.getAbsolutePath(),auxFile.getAbsolutePath());
 

解决方案

你想要的是......

 新建文件(uri.getPath());
 

...而不是...

 新建文件(uri.toString());
 

What's the easiest way to convert from a file: android.net.Uri to a File in Android?

Tried the following but it doesn't work:

 final File file = new File(Environment.getExternalStorageDirectory(), "read.me");
 Uri uri = Uri.fromFile(file);
 File auxFile = new File(uri.toString());
 assertEquals(file.getAbsolutePath(), auxFile.getAbsolutePath());

解决方案

What you want is...

new File(uri.getPath());

... and not...

new File(uri.toString());

这篇关于转换文件:URI在Android文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆