fileExist method
文件是否存在
Implementation
Future<bool> fileExist({required String fileName, String? filePath, FileMode? fileMode}) async {
// create({bool recursive: false})创建文件
// createSync({bool recursive: false}) 同步创建文件
// 可选命名参数:recursive 默认false,
// 若为true 则路径中有目录不存在时 会递归创建目录
// 若为false 则路径中的目录不存在时 会报错
try {
File? file;
if (Platform.isWindows) {
file = await getLocalSupportFile(fileName: fileName, filePath: filePath);
} else if (Platform.isAndroid) {
final exFile = await getExternalStorageFile(fileName: fileName, filePath: filePath);
if (exFile == null) {
file = await getLocalTemporaryFile(fileName: fileName, filePath: filePath);
} else {
file = exFile;
}
} else {
file = await getLocalDocumentFile(fileName: fileName, filePath: filePath);
}
if (file == null) {
return false;
}
return await file.exists();
} catch (e) {
return false;
}
}