是否可以从DocumentFile获取常规文件? [英] Is it possible to get a regular File from DocumentFile?
问题描述
对于Android,以下代码返回一个Uri,该Uri可用于创建与目录相对应的DocumentFile.
For Android, the following code returns a Uri that can be used to create DocumentFile corresponding to a directory.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, REQUEST_CODE_CUSTOM_FOLDER);
由于库的许多方法都要求参数为java.io.File,所以我想知道是否可以从DocumentFile中获取java.io.File.
Since many methods of a library requires a parameter to be java.io.File, I am wondering if one can get a java.io.File from a DocumentFile.
作为示例,返回的文档树Uri treeUri如下:
As an example, an returned document tree Uri treeUri is the following:
treeUri.getPath():/tree/primary:DCIM/deeper/evendeeper
treeUri.toString(): content://com.android.externalstorage.documents/tree/primary%3ADCIM%2Fdeeper%2Fevendeeper
以下是ADM中显示的目录:
The following is the directory shown in ADM:
推荐答案
以下代码返回一个Uri,该Uri可用于创建与目录相对应的DocumentFile
the following code returns a Uri that can be used to create DocumentFile corresponding to a directory
不,不是.它返回一个Uri
,可用于创建与文档树相对应的DocumentFile
.不需要它表示文件系统上的目录.表示文档树的位置和方式取决于用户选择的DocumentsProvider
.该提供程序可以执行它想要代表树的任何操作(例如,使用数据库,使用对服务器的REST调用).
No, it does not. It returns a Uri
that can be used to create a DocumentFile
corresponding to a tree of documents. There is no requirement for it to represent a directory on a filesystem. Where and how the document tree is represented is up to the DocumentsProvider
that the user chose. That provider can do whatever it wants to represent the tree (e.g., use a database, use REST calls to a server).
我想知道是否可以从DocumentFile中获取java.io.File.
I am wondering if one can get a java.io.File from a DocumentFile.
否,因为没有文件.
这篇关于是否可以从DocumentFile获取常规文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!