Api访问目录 使用起来非常简单 先看看怎么生成DocumentFile对象 DocumentFile documentFile = DocumentFile.fromTreeUri(context DocumentFile.fromFile(); DocumentFile.isDocumentUri(); 看名字就明白了,但是我们有的的是一个文件夹uri,当然使用这个方法来生成DocumentFile (DocumentFile documentFile) { this.documentFile = documentFile; } } for (DocumentFile documentFile_inner : documentFile.listFiles()) { file file 可以生成正确的DocumentFile对象了,我们又可以用它来做一些好玩的东西了,比如直接通过path生成DocumentFile对象对某个文件获取大小啊、判断存在状态啊,等等。
* @return */ @GetMapping("/index") public String index(Model model){ List<DocumentFile * @param wos // */ // public void loadFile(eWebOfficeServer wos,String recordId){ // DocumentFile "); byte[] a_FileBody = wos.WebMsgGetStream("FileBody"); wos.WebMsgClear(); DocumentFile documentFile = documentFileService.getByRecordId(s_RecordID); documentFile.setdFilebody(a_FileBody ); int update = documentFileService.update(documentFile); //测试写入 // testWrite(
java.util.zip.ZipOutputStream; /** * xml文档 转换 Word */ public class XmlToDocx { /** * * @param documentFile param toFilePath 需要导出的文件路径 * @throws Exception */ public static void outDocx(File documentFile word/document.xml".equals(next.toString())) { InputStream in = new FileInputStream(documentFile
1.0.0 -> 1.3.0 | | +--- androidx.core:core:1.0.0 -> 1.9.0 (*) | | +--- androidx.documentfile :documentfile:1.0.0 | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0 | |
1.0.0 -> 1.3.0 | | +--- androidx.core:core:1.0.0 -> 1.8.0 (*) | | +--- androidx.documentfile :documentfile:1.0.0 | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0 | | | +--- com.android.support:support-compat:28.0.0 (*) | +--- com.android.support:documentfile 1.0.0 -> 1.3.0 | | +--- androidx.core:core:1.0.0 -> 1.8.0 (*) | | +--- androidx.documentfile :documentfile:1.0.0 | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0 | |
1.0.0 -> 1.3.0 | | +--- androidx.core:core:1.0.0 -> 1.9.0 (*) | | +--- androidx.documentfile :documentfile:1.0.0 | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0 | |
exclude 'META-INF/androidx.customview_customview.version' exclude 'META-INF/androidx.documentfile_documentfile.version
1.0.0 -> 1.3.0 | | +--- androidx.core:core:1.0.0 -> 1.8.0 (*) | | +--- androidx.documentfile :documentfile:1.0.0 | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0 | |
1.0.0 -> 1.3.0 | | +--- androidx.core:core:1.0.0 -> 1.9.0 (*) | | +--- androidx.documentfile :documentfile:1.0.0 | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0 | |
exclude 'META-INF/androidx.customview_customview.version' exclude 'META-INF/androidx.documentfile_documentfile.version
exclude 'META-INF/androidx.customview_customview.version' exclude 'META-INF/androidx.documentfile_documentfile.version
' annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' implementation 'androidx.documentfile :documentfile:1.0.1' } 在AndroidManifest.xml中申请读写权限: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE
| +--- com.android.support:support-compat:28.0.0 (*) | | | +--- com.android.support:documentfile -- com.android.support:versionedparcelable:{strictly 28.0.0} -> 28.0.0 (c) +--- com.android.support:documentfile
1.0.0 -> 1.3.0 | | +--- androidx.core:core:1.0.0 -> 1.8.0 (*) | | +--- androidx.documentfile :documentfile:1.0.0 | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0 | |
1.0.0 -> 1.3.0 | | +--- androidx.core:core:1.0.0 -> 1.8.0 (*) | | +--- androidx.documentfile :documentfile:1.0.0 | | | \--- androidx.annotation:annotation:1.0.0 -> 1.3.0 | |
ACTION_OPEN_DOCUMENT_TREE的intent,拉起DocumentUI让用户主动授权的方式 获取,获得用户主动授权之后,应用就可以临时获得该目录下面的所有文件和目录的读写权限,可以通过DocumentFile = null) { savePersistablePermission(treeUri)//将获取的权限持久化保存 val root = DocumentFile.fromTreeUri Intent.FLAG_GRANT_WRITE_URI_PERMISSION) Log.d(TAG, "已经获得永久访问权限") val root = DocumentFile.fromTreeUri