[library] Forked from DocumentFile, but more powerful
This repository has been archived on 2024-01-16. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
arkon 7c257e1c64 Ignore case when finding existing directory when trying to create a new one 2023-11-27 09:15:32 -05:00
app Remove boilerplate/broken tests 2021-04-11 13:35:24 -04:00
gradle/wrapper Various updates 2021-04-11 13:31:47 -04:00
library Ignore case when finding existing directory when trying to create a new one 2023-11-27 09:15:32 -05:00
.gitignore Prepare for jitpack 2016-04-10 15:09:39 +08:00
LICENSE Add license, notice and readme 2016-04-10 20:43:09 +08:00
NOTICE Update notice 2016-04-11 15:54:27 +08:00
README.md Update readme 2016-11-28 01:38:31 +08:00
build.gradle Various updates 2021-04-11 13:31:47 -04:00
gradle.properties Various updates 2021-04-11 13:31:47 -04:00
gradlew Prepare for jitpack 2016-04-10 15:09:39 +08:00
gradlew.bat Prepare for jitpack 2016-04-10 15:09:39 +08:00
settings.gradle Prepare for jitpack 2016-04-10 15:09:39 +08:00



UniFile 是基于 android.support.v4.provider.DocumentFile,而且更好用。

The UniFile is forked from android.support.v4.provider.DocumentFile, but more powerful.


  • 添加其他文件 uri 支持
    • 支持所有 ContentProvider 的 uri
    • 支持 asset 文件的 urifile:///android_asset/text/uccu.txt
    • 支持 resource 文件的 uriandroid.resource://com.hippo.unifile.example/2130903040
  • 添加 getFilePath()
  • 添加 listFiles(FilenameFilter)
  • 添加 openOutputStream()openOutputStream(boolean append)openInputStream()
  • 添加 createRandomAccessFile(String mode)
  • 删除了 createFile 中 mimeType 参数
  • 修改 createFilecreateDirectory 特性,避免出现文件名后添加 (1) 的现象

The differences:

  • Add other file uri support
    • Support all uri from ContentProvider
    • Support all asset file uri, like file:///android_asset/text/uccu.txt
    • Support all resource file uri, like android.resource://com.hippo.unifile.example/2130903040
  • Add getFilePath()
  • Add listFiles(FilenameFilter)
  • Add openOutputStream()openOutputStream(boolean append)openInputStream()
  • Add createRandomAccessFile(String mode)
  • Remove mimeType in createFile function
  • Avoid filename ending with (1) in createFilecreateDirectory


在最外面的 build.gradle 里加上 jitpack别加到 buildscript 里了。

Add jitpack repository in top build.gradle, DO NOT ADD IT TO buildscript.

allprojects {
    repositories {
        maven { url "https://jitpack.io" }

在项目 build.gradle 里添加 UniFile 依赖。

Add UniFile as dependency in project build.gradle.

dependencies {
    compile 'com.github.seven332:unifile:1.0.0'


Use UniFile in your code:

// 从 Uri 创建 UniFile
// Create UniFile from Uri
file = UniFile.fromUri(context, uri);

// 从 File 创建 UniFile
// Create UniFile from File
file = UniFile.fromFile(f);

// 从 asset path 创建 UniFile
// Create UniFile from asset path
file = UniFile.fromAsset(assetManager, path);

// 从 resource id 创建 UniFile
// Create UniFile from resource id
file = UniFile.fromResource(context, resId);

// 获取原始文件路径
// Get origin file path
path = file.getFilePath();

// 创建随机访问文件
// Create random access file
raf = file.createRandomAccessFile("rw");


Copyright (C) 2015-2016 Hippo Seven

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at


Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.