在Android中从a转换为a的最简单方法是file: android.net.Uri什么?File
file:
android.net.Uri
File
尝试了以下但它不起作用:
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());
你想要的是…
new File(uri.getPath());
… 并不是…
new File(uri.toString());
注意: uri.toString()返回格式为:的字符串"file:///mnt/sdcard/myPicture.jpg",而uri.getPath()返回格式为:的字符串"/mnt/sdcard/myPicture.jpg"。
uri.toString()
"file:///mnt/sdcard/myPicture.jpg"
uri.getPath()
"/mnt/sdcard/myPicture.jpg"