writeBytes method
写入数据
Implementation
Future<void> writeBytes(List<int> bytes, File file, FileMode? fileMode) async {
// create({bool recursive: false})创建文件
// createSync({bool recursive: false}) 同步创建文件
// 可选命名参数:recursive 默认false,
// 若为true 则路径中有目录不存在时 会递归创建目录
// 若为false 则路径中的目录不存在时 会报错
final fileExists = await file.exists();
if (!fileExists) {
await file.create(recursive: true);
}
//写入字节数组
await file.writeAsBytes(bytes,
flush: true, // 如果flush设置为`true` 则写入的数据将在返回之前刷新到文件系统
mode: fileMode ?? FileMode.append); // 写入的模式 append(追加写入) read(只读) write(读写) writeOnly(只写) writeOnlyAppend(只追加)
}