FileUtils class

  • @Author: chuxiong
  • @Created at: 2022/10/31 11:02 上午
  • @Email:
  • description 文件工具类

Constructors

FileUtils.new()
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
TAG String
final

Methods

cleanExpiredLog(String logPath, int retentionTime) → void
清除过期log file:文件
cleanLog() → void
clearFileData(String filePath) Future<bool>
清除缓存数据
createBase64FromFile(File file) Future<String>
createDir(String path) Directory?
同步创建文件
createDirSync(String path) Future<Directory?>
异步创建文件
createFileFromBase64(String base64Str) Future<File>
deleteFileData(String filePath) Future<bool>
删除缓存文件
deleteLog({int saveDays = 3}) → void
删除日志 默认保留3天
fileExist({required String fileName, String? filePath, FileMode? fileMode}) Future<bool>
文件是否存在
getExternalStorageFile({required String fileName, String? filePath}) Future<File?>
外部存储目录,Android 特有,删除应用不会删除该目录 应用程序可以访问顶层存储的目录的路径。在发出这个函数调用之前,应该确定当前操作系统,因为这个功能只在Android上可用。 在iOS上,这个函数抛出一个UnsupportedError,因为它不可能访问应用程序的沙箱之外。 在Android上,它使用“getExternalStorageDirectory”API。
getFile({required String fileName, String? filePath, FileMode? fileMode}) Future<File?>
文件是否存在
getFileList() Future<List<File>>
getFileName(String path) String
getLocalDocumentDir() Future<String?>
获取应用程序的目录,用于存储只有它可以访问的文件。只有当应用程序被删除时,系统才会清除目录。 在iOS上,它使用“NSDocumentDirectory”API。如果数据不是用户生成的,请考虑使用GetApplicationSupportDirectory。 在Android上,这在上下文中使用了“getDataDirectory”API。如果数据对用户可见,请考虑改用getExternalStorageDirectory。 文档目录: /data/user/0/com.xx.xxx/xxx
getLocalDocumentFile({required String fileName, String? filePath}) Future<File?>
获取文档目录文件,用于存储只能由该应用访问的文件,系统不会清除该目录,只有在删除应用时才会消失。
getLocalSupportDir() Future<String?>
获取应用程序支持路径
getLocalSupportFile({required String fileName, String? filePath}) Future<File?>
获取应用程序支持目录,只能由该应用访问,用于不想向用户公开的文件,也就是你不想给用户看到的文件可放置在该目录中, 系统不会清除该目录,只有在删除应用时才会消失。 应用程序可以放置应用程序支持文件的目录的路径。 对不希望向用户公开的文件使用此选项。您的应用程序不应将此目录用于用户数据文件。 在iOS上,它使用“NSApplicationSupportDirectory”API。如果此目录不存在,则自动创建。 在Android上,此函数抛出一个UnsupportedError。 windows 和sp 同目录
getLocalTemporaryDir() Future<String?>
获取本地临时文件路径
getLocalTemporaryFile({required String fileName, String? filePath}) Future<File?>
获取临时目录文件,只能由该应用访问,系统可随时清除的临时目录(缓存) 指向设备上临时目录的路径,该目录没有备份,适合存储下载文件的缓存。 此目录中的文件可以随时清除。这不会返回一个新的临时目录。 相反,调用者负责在这个目录中创建(和清理)文件或目录。这个目录的作用域是调用应用程序。 在iOS上,它使用“NSCachesDirectory”API。 在Android上,它在上下文中使用“getCacheDir”API。 临时目录: /data/user/0/com.xx.xxx/cache
getPlatformPath() Future<String?>
获取平台默认存储路径
getWriteIoSink({required File file, FileMode? fileMode}) Future<IOSink?>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readBySink(File file, FileMode? fileMode) Future<String>
以流的方式读取文件
readBytes(File file) Future<List<int>>
以字节形式读取 readAsBytesSync() 同步读取 一次性读取整个文件,缺点就是如果文件太大的话,可能造成内存空间的压力。
readFile(String filePath) File
创建file文件
readLines(File file) Future<List<String>>
按行读取 返回字符串数组 readAsLinesSync() 同步读取 一次性读取整个文件,缺点就是如果文件太大的话,可能造成内存空间的压力。
readString(File file) Future<String>
读取值 以字符串形式读取 readAsStringSync() 同步读取 一次性读取整个文件,缺点就是如果文件太大的话,可能造成内存空间的压力。
readStringCustomFile(String filePath) Future<String?>
获取自定义路径文件存中的数据 使用async、await,返回是一个Future对象
toString() String
A string representation of this object.
inherited
writeBySink(File file, String content, FileMode? fileMode) → void
为文件创建一个IOSink,使用结束需要释放资源 mode: FileMode.append,// 写入的模式 append(追加写入,如果文件存在在末尾追加,如果文件不存在创建) read(只读) write(读写,如果文件存在覆盖,如果文件不存在创建) writeOnly(只写,如果文件存在覆盖,如果文件不存在创建) writeOnlyAppend(只追加,如果文件存在在末尾追加,如果文件不存在创建)
writeBytes(List<int> bytes, File file, FileMode? fileMode) Future<void>
写入数据
writeJsonCustomFile(Object obj, String filePath) Future<File?>
写入json文件,自定义路径
writeString({required String str, required String fileName, String? filePath, FileMode? fileMode}) Future<File?>
写入数据
writeStringFile(String string, String filePath) Future<File?>
利用文件存储字符串,自定义路径
zipFiles(String? zipName) Future<File?>
压缩日志文件

Operators

operator ==(Object other) bool
The equality operator.
inherited