title: Retrieve File Size in Android programmatically
body: <p>I'm looking for a way to read 'PDF' size. so far I have attempted the following approaches:</p>
  
  <p><strong>Note:</strong> all the permissions are in place and i do have access to the file.</p>
  
  <p><strong>1) using file length</strong></p>
  
  <pre><code>path = "/storage/emulated/0/Download/c4611_sample_explain.pdf";
  File file = new File(path);
  int file_size = Integer.parseInt(String.valueOf(file.length() / 1024));
  </code></pre>
  
  <p><strong>RESULT :</strong>
  It works on images, but returns 0 on pdf files</p>
  
  <p><strong>2) using cursor</strong></p>
  
  <pre><code>Uri uri = Uri.fromFile(new File(path));
  Cursor cursor = contentResolver.query(uri, null, null, null, null);
  String size= "null";
  if (cursor != null) {
      size=cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.SIZE));
      cursor.close();
  }
  </code></pre>
  
  <p><strong>RESULT :</strong></p>
  
  <pre><code>size: null 
  path: /storage/emulated/0/Download/c4611_sample_explain.pdf 
  URI: file:///storage/emulated/0/Download/c4611_sample_explain.pdf
  
  UPDATE: Cursor returns null
  </code></pre>
  
  <p>Is there something else I should do ?</p>