以下代码采用String
并将内容保存到现有文件中Uri
。这些代码在Android pre API 29之前运行良好。
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
}
}
使用Android API 29+,该行为不固定。例如,如果第一次使用some调用该函数text
,则文件将正确保存。但是,如果第二次text
为空,则不会保存文件。
有什么帮助吗?
cr.openOutputStream(existingSourceUri, "wt");
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句