title: Problems reading inputStream from a Uri and sending through an outputStream android
body: <p>Good day, I am trying to send a file from an <code>SDCard</code> through an <code>OutputStream</code>. I intend to get the <code>URI</code> from the file name which I have and then use an <code>InputStream</code> to read the <code>URI</code> and convert to bytes in other to send. Currently the code is stuck in get <code>InputStream</code> (As commented below) and nothing happens. </p>
  
  <p>Also, I don't know if I am using the <code>URI</code> correctly to get the actual path of the file to send.</p>
  
  <p>Please, any help will be greatly appreciated because I have been stuck here for some time now. Thank you. </p>
  
  <p>My code:</p>
  
  <pre><code>public void sendFile() {
      Log.d(TAG, "sending data");
      InputStream inputStream = null;
      String filePath = Environment.getExternalStorageDirectory()
            .toString() + "/" + files.get(0);
      Log.d(TAG, "filepath is" + filePath);
  
      Uri uri = Uri.parse(filePath);
  
      Log.d(TAG, "obtained input stream here in Activity");
      Log.d(TAG, "Uri here is" + uri);  // nothing happens after here, Basically stuck!!
      try {
          inputStream = getContentResolver().openInputStream(uri);
          ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
          Log.d(TAG, "obtained input stream here in Activity");
  
          int buffersize = 1024;
          byte[] buffer = new byte[buffersize];
  
          int len = 0;
          while ((len = inputStream.read(buffer)) != -1) {
              byteBuffer.write(buffer, 0, len);
          }
  
          AppServices.write(byteBuffer.toByteArray());
  
      } catch (IOException e) {
          e.printStackTrace();
      }
      finally {
          if (inputStream != null) {
              try {
                  inputStream.close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>