title: FileNotFoundException When Uploading File (Non-image) To App
body: <p>I've been trying to allow the user to upload a file (PDF) to my app for eventual upload to my Parse server, but every time I attempt to create a filestream/buffered input stream, I get a FileNotFoundException, claiming that there is 'no such file or directory'. One of my logged file paths appears below:</p>
  
  <p><em>/storage/emulated/0/Android/data/com.parse.starter/files/Eloquent_JavaScript.pdf</em></p>
  
  <p>I have no idea as to why it's giving me this bad path. This is my MainActivity (my only activity). I understand that not all files will be stored internally on the phone -- that's why I used certain support methods for my onActivityResult class. I've been struggling to isolate my issue because I haven't been working with files for very long, so things are still relatively new to me. Again, I apologize for all the code. Any assistance is appreciated.</p>
  
  <p><strong>Intent Method</strong></p>
  
  <pre><code>public void getFile() 
  {
  
       Intent intent = new Intent();
       intent.setType("application/pdf");
       intent.setAction(Intent.ACTION_GET_CONTENT);
  
       startActivityForResult(intent, 1);
  
   }
  </code></pre>
  
  <p><strong>onActivityResult Method</strong></p>
  
  <pre><code>public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          filename = null;
          if (requestCode == 1) {
              if (resultCode == RESULT_OK) {
                  try {
                      Uri uri = data.getData();
  
                      if (1 &gt; 1) {
                          Toast.makeText(this,"The selected file is too large. Select a new file with size less than 2mb",Toast.LENGTH_LONG).show();
                      } else {
                          String mimeType = getContentResolver().getType(uri);
                          if (mimeType == null) {
                              String path = getPath(this, uri);
                              if (path == null) {
                                  filename = uri.toString().substring(uri.toString().lastIndexOf("/") + 1);
                              } else {
                                  File file = new File(path);
                                  filename = file.getName();
                              }
                          } else {
                              Uri returnUri = data.getData();
                              Cursor returnCursor = getContentResolver().query(returnUri, null, null, null, null);
                              int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
                              int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
                              returnCursor.moveToFirst();
                              filename = returnCursor.getString(nameIndex);
                              String size = Long.toString(returnCursor.getLong(sizeIndex));
                          }
                          File fileSave = getExternalFilesDir(null);
                          String sourcePath = getExternalFilesDir(null) + "/" + filename;
                          sourcePath = sourcePath.substring(sourcePath.lastIndexOf("data") + 4, sourcePath.length());
                          Log.i("PATH", sourcePath);
                          Log.i("NAME", filename);
  
                          // create byte array
                          File file = new File(sourcePath);
                          int size = (int) file.length();
                          byte[] bytes = new byte[size];
                          try {
                              BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
                              buf.read(bytes, 0, bytes.length);
                              buf.close();
                          } catch (FileNotFoundException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          } catch (IOException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                          // byte array created
                  }
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }
      }
  </code></pre>
  
  <p><strong>Here Are Some Support Methods for the onActivityResult method</strong></p>
  
  <pre><code>    public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
          Cursor cursor = null;
          final String column = "_data";
          final String[] projection = { column };
          try {
              cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
              if (cursor != null &amp;&amp; cursor.moveToFirst()) {
                  final int index = cursor.getColumnIndexOrThrow(column);
                  return cursor.getString(index);
              }
          } finally {
              if (cursor != null)
                  cursor.close();
          }
          return null;
      }
  
      public static boolean isExternalStorageDocument(Uri uri) {
          return "com.android.externalstorage.documents".equals(uri.getAuthority());
      }
  
      /**
       * @param uri The Uri to check.
       * @return Whether the Uri authority is DownloadsProvider.
       */
      public static boolean isDownloadsDocument(Uri uri) {
          return "com.android.providers.downloads.documents".equals(uri.getAuthority());
      }
  
      /**
       * @param uri The Uri to check.
       * @return Whether the Uri authority is MediaProvider.
       */
      public static boolean isMediaDocument(Uri uri) {
          return "com.android.providers.media.documents".equals(uri.getAuthority());
      }
  
      /**
       * @param uri The Uri to check.
       * @return Whether the Uri authority is Google Photos.
       */
      public static boolean isGooglePhotosUri(Uri uri) {
          return "com.google.android.apps.photos.content".equals(uri.getAuthority());
      }
  </code></pre>