Kam*_*mil 4 android uri outputstream file android-contentresolver
以下代码获取 aString
并将内容保存到现有文件中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
}
}
Run Code Online (Sandbox Code Playgroud)
对于 Android API 29+,行为不稳定。例如,如果第一次使用 some 调用该函数text
,则该文件将被正确保存。但是,如果第二次text
为空,则不会保存文件。
有什么帮助吗?
bla*_*pps 11
cr.openOutputStream(existingSourceUri, "wt");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1520 次 |
最近记录: |