將文件:Uri轉換為Android中的文件什么是從一個轉換的最簡單的方法file: android.net.Uri,以一個File在Android的?嘗試以下但它不起作用: 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());
3 回答

富國滬深
TA貢獻1790條經驗 獲得超9個贊
你想要的是......
new File(uri.getPath());
... 并不是...
new File(uri.toString());
注意: uri.toString()
返回格式為:的String "file:///mnt/sdcard/myPicture.jpg"
,而uri.getPath()
返回格式為String的字符串:"/mnt/sdcard/myPicture.jpg"
。
- 3 回答
- 0 關注
- 1419 瀏覽
添加回答
舉報
0/150
提交
取消