颤振:无法通过 file.copy 将配置单元复制到存储

问题描述

我正在尝试将 hive Box 复制到我的移动存储中。接受足够的权限后,我运行我的方法

  Future<void> exportVocabsDb() async {
    final dir = await getExternalStorageDirectory();
    final evbDirectory =
        await Directory('${dir!.path}/evb').create(recursive: true);
    hiveService.backupHiveBox<VocabularyModel>(
        VOCABULARY_Box,evbDirectory.path);
  }

和:

  Future<void> backupHiveBox<T>(String BoxName,String backupPath) async {
    if (!Hive.isBoxOpen(BoxName)) {}
    final Box = await Hive.openBox<T>(BoxName);
    final BoxPath = Box.path;
    await Box.close();

    try {
      File('$BoxPath-${DateTime.Now().toUtc().toIso8601String()}')
          .copy(backupPath);
    } finally {
      await Hive.openBox<T>(BoxName);
    }
  }

但是我收到了这个错误

[ERROR:Flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: filesystemexception: Cannot copy file to '/storage/emulated/0/Android/data/com.example.english_vocabulary_builder/files/evb',path = '/data/user/0/com.example.english_vocabulary_builder/app_Flutter/vocabularyBox.hive-2021-07-31T09:45:10.236593Z' (OS Error: No such file or directory,errno = 2)

这是医生:

Doctor summary (to see all details,run Flutter doctor -v):
[✓] Flutter (Channel stable,2.2.3,on Linux,locale en_US.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    ✗ Android license status unkNown.
      Run `Flutter doctor --android-licenses` to accept the SDK licenses.
      See https://Flutter.dev/docs/get-started/install/linux#android-setup for more details.
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] Android Studio
[✓] VS Code (version 1.58.2)
[✓] Connected device (2 available)

! Doctor found issues in 1 category.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)