[关闭]
@PheonixHkbxoic 2017-05-11T08:43:27.000000Z 字数 575 阅读 1122

File,URI,path互转

Android


URI

Uri=>file

  1. file = new File(new URI(uri.toString()));

uri=>path

  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

file=>uri

  1. URI uri = file.toURI();

file=>path

  1. String path = file.getPath();

PATH

path=>uri

  1. Uri uri = Uri.parse(path);

path=>file

  1. File file = new File(path);
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注