content: package com.example.chaomianqiandao.utils;
  
  import android.content.ContentResolver;
  import android.content.Context;
  import android.database.Cursor;
  import android.net.Uri;
  import android.provider.MediaStore;
  import android.text.TextUtils;
  
  import java.io.File;
  
  public  class Fileutils {
      public static String checkDirPath(String dirPath) {
          if (TextUtils.isEmpty(dirPath)) {
              return "";
          }
          File dir = new File(dirPath);
          if (!dir.exists()) {
              dir.mkdirs();
          }
          return dirPath;
      }
      public static String getRealFilePathFromUri(final Context context, final Uri uri) {
          if (null == uri) return null;
          final String scheme = uri.getScheme();
          String data = null;
          if (scheme == null) {
              data = uri.getPath();
          }
          else if (ContentResolver.SCHEME_FILE.equalsIgnoreCase(scheme)) {
              data = uri.getPath();
          } else if (ContentResolver.SCHEME_CONTENT.equalsIgnoreCase(scheme)) {
              Cursor cursor = context.getContentResolver().query(uri, new String[]{MediaStore.Images.ImageColumns.DATA}, null, null, null);
              if (null != cursor) {
                  if (cursor.moveToFirst()) {
                      int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
                      if (index > -1) {
                          data = cursor.getString(index);
                      }
                  }
                  cursor.close();
              }
          }
          return data;
      }
  }
  