使用经典的FileSystem应用程序接口,我们可以获得一个带有附加参数的输出流,以写入到文件的末尾。
下面是我用来访问这些文件的代码:
传统文件系统API:
boolean append = true;
File target = new File(...);
OutputStream outStream = new FileOutputStream(target, append);SAF API:
boolean append = true;
File target = new File(...);
DocumentFile targetDocument = getDocumentFile(target, false, context);
OutputStream outStream = context.getContentResolver().openOutputStream(targetDocument.getUri());但是我在SAF API中没有append参数。
如何使用SAF API附加到文件?
发布于 2017-04-10 12:24:41
使用此method。看看mode的文档,您可以将"wa"作为附加到任意文件的模式传递。
然而,"wa"是一个复杂的模式,正如documentation中指出的那样,它需要文件是可查找的,但ParcelFileDescriptor只有在从文件对象获取时才是可查找的,所以直到Android O才能支持它,只有本地存储支持的提供商才能支持它。
openFile()和openAssetFile()都被引用的原因是在DocumentsProvider的源代码中,因为它们都委托给openDocument(),所以两个文档都适用。
https://stackoverflow.com/questions/41807615
复制相似问题