title: Android: overwrite file from an existing URI in API 29
body: <p>The following codes take a <code>String</code> and save the content to an existing file <code>Uri</code>.  The codes were working well in Android pre API 29.</p>
  <pre><code>public void saveFile(String text, Uri existingSourceUri)
  {
      try {
  
      ContentResolver cr = getContentResolver();
      OutputStream os = cr.openOutputStream(existingSourceUri);
  
      os.write(text.getBytes());
      os.flush();
      os.close();
  
  
      } catch (Exception e) {
         //show error message
      }
  }
  </code></pre>
  <p>With Android API 29+, the behavior is erratic. For example, if the function is called the first time with some <code>text</code>, the file is properly saved. However, if the second time <code>text</code> is blank, the file is not saved.</p>
  <p>Any help?</p>