Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Android中将文件保存到Uri路径_Java_Android_Uri_Outputstream_File Access - Fatal编程技术网

Java 如何在Android中将文件保存到Uri路径

Java 如何在Android中将文件保存到Uri路径,java,android,uri,outputstream,file-access,Java,Android,Uri,Outputstream,File Access,我有一个用户通过ACTION\u OPEN\u DOCUMENT\u树授予的Uri路径 我将此Uri保存为SharedReferences的字符串表示形式。现在,我想将一个内部文件复制到该文件夹的子文件夹中,并为其指定与内部文件相同的文件名 我使用此命令将文档文件发送到uriTree: Uri folder = Uri.parse(<getmysaveduristring>); DocumentFile file = DocumentFile.fromTreeUri(c, folde

我有一个用户通过ACTION\u OPEN\u DOCUMENT\u树授予的Uri路径

我将此Uri保存为SharedReferences的字符串表示形式。现在,我想将一个内部文件复制到该文件夹的子文件夹中,并为其指定与内部文件相同的文件名

我使用此命令将文档文件发送到uriTree:

Uri folder = Uri.parse(<getmysaveduristring>);
DocumentFile file = DocumentFile.fromTreeUri(c, folder);
urifolder=Uri.parse();
DocumentFile=DocumentFile.fromtreeeuri(c,文件夹);
如何编辑文档文件以包含子文件夹和文件名

URI和文档文件现在让我很困惑。

是这样理解的:

DocumentFile subDirFile = file.createDirectory(subDir);
DocumentFile actualFile = subDirFile.createFile("*/*", dst.getName());
然后使用

OutputStream out = c.getContentResolver().openOutputStream(actualFile.getUri());
打开文件

我花了一段时间才明白使用文档文件是必要的