title: Uri vs File vs StringPath in android
body: <p>Recently I am doing app deals with saving image and loading image on external storage. I am quite confused with <code>Uri</code>, <code>File</code> and <code>StringPath</code>. </p>
  
  <p>For example, when load image from Gallery, it uses <code>Uri</code>.</p>
  
  <pre><code>if (requestCode == RESULT_LOAD_IMAGE &amp;&amp; resultCode == RESULT_OK &amp;&amp; null != data) { //Browse Gallery is requested
      //Get the path for selected image in Gallery
      Uri selectedImage = data.getData();
      String[] filePathColumn = { MediaStore.Images.Media.DATA };
  
      //Access Gallery according to the path
      Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
      cursor.moveToFirst();
  
      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
      String picturePath = cursor.getString(columnIndex);
      cursor.close();
  
      loadImage(picturePath);         //load picture according the path
      image_View.setImageBitmap(pic); //Show the selected picture
  }
  </code></pre>
  
  <p>Then when decode the image, it uses <code>StringPath</code>.</p>
  
  <pre><code>private void loadImage(String picturePath) {
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
  
      BitmapFactory.decodeFile(picturePath,options);
      int height_ = options.outHeight;
      int width_ = options.outWidth;
      float ratio = width_/height_;
      int width = 480;
      int height = 480;
      if(width_&gt;height_){
          height = Math.round(width / ratio);
      }else{
          width = Math.round(width*ratio);
      }
  
      options.inSampleSize = calculateInSampleSize(options, width, height);
      options.inJustDecodeBounds = false;
      pic=BitmapFactory.decodeFile(picturePath,options);
  }
  </code></pre>
  
  <p>Then when read byte from file, it uses <code>File</code>.</p>
  
  <pre><code>File cacheDir = getBaseContext().getCacheDir();
  //Form a directory with a file named "pic"
  File f = new File(cacheDir, "pic");
  
  try {
      //Prepare output stream that write byte to the directory
      FileOutputStream out = new FileOutputStream(f);
      //Save the picture to the directory
      pic.compress(Bitmap.CompressFormat.JPEG, 100, out);
      out.flush();
      out.close();
  } catch (FileNotFoundException e) {
      e.printStackTrace();
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>So, what is the difference? Is it just different in usage but represent same directory?</p>