以下代码采用String
并将内容保存到现有文件中Uri
。这些代码在 Android 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+,行为不稳定。例如,如果第一次调用该函数时有一些text
,文件已正确保存。然而,如果第二次text
为空,文件未保存。
有什么帮助吗?
cr.openOutputStream(existingSourceUri, "wt");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)