title: Android code not creating file. No such file or directory found error
body: <p>I've got the following code to write a captured image to the SD card</p>
  
  <pre><code>private static File getOutputMediaFile(){
      File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
              Environment.DIRECTORY_PICTURES), "AppName");
  
      if (!mediaStorageDir.exists()){
          if (!mediaStorageDir.mkdirs()){
              return null;
          }
      }
  
      String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
      return new File(mediaStorageDir.getPath() + File.separator +
              "IMG_"+ timeStamp + ".jpg");
  }
  </code></pre>
  
  <p>which is used as follows:</p>
  
  <pre><code>public void takePicture(){
      i= new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //Open camera
      file = Uri.fromFile(getOutputMediaFile());
      i.putExtra(MediaStore.EXTRA_OUTPUT, file);
      startActivityForResult(i, 100);
  }
  </code></pre>
  
  <p>After the image is captured, the path to the file is sent to the following function:</p>
  
  <pre><code>public void sendForUpload(String uploadUrl, String path){
      File dir = Environment.getExternalStorageDirectory();
      File imgFile = new File(dir, path);
      sendFile(uploadUrl, imgFile);
  }
  public void sendFile(String uploadUrl, File file){
      Log.d(GlobalClass.TAG, "File has arrived here");
      Log.d(GlobalClass.TAG, file.toString());
      byte[] fileData1 = new byte[(int) file.length()];
      FileInputStream fileInputStream;
      try{
          fileInputStream = new FileInputStream(file);
          fileInputStream.read(fileData1);
          fileInputStream.close();
      }catch (Exception e){
          Log.d("Error", e.getMessage());
      }
      .... // Upload
  }
  </code></pre>
  
  <p>The <code>try</code> block here fails and the log shows the error:</p>
  
  <pre><code>D/Error: /storage/emulated/0/storage/emulated/0/Pictures/AppName/IMG_20160516_120506.jpg: open failed: ENOENT (No such file or directory)
  </code></pre>
  
  <p>How do I read the file into <code>sendFile()</code>?</p>