Flutter检查文件存在于ApplicationDocumentsDirectory中

时间:2019-03-20 11:24:48

标签: android ios flutter

下载前如何检查ApplicationDocumentsDirectory中文件和目录的存在?

1 个答案:

答案 0 :(得分:0)

import 'dart:io';
import 'package:path_provider/path_provider.dart';

String fileName = "file.jpg";
String dir = (await getApplicationDocumentsDirectory()).path;
String savePath = '$dir/$fileName';

//for a directory: await Directory(savePath).exists();
if (await File(savePath).exists()) {
    print("File exists");        
} else {
    print("File don't exists");
}