Flutter -FileSystemException:无法打开文件,路径='/data/data/com.decimal.dataonflutter/databases/dataOn.db'(OS错误:没有这样的文件

时间:2019-02-28 05:59:24

标签: flutter

写入文件时,它在writeAsbytes上引发异常:无法打开文件。它适用于android API 22以上版本,但不适用于android API 22 Samsung设备上。

var databasesPath = await getDatabasesPath();
    String path = join(databasesPath, DB_NAME);
    if (FileSystemEntity.typeSync(path) == FileSystemEntityType.notFound) {
      // Load database from asset and copy
      ByteData data = await rootBundle.load(join('assets', DB_NAME));
      List<int> bytes =
          data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);

      // Save copied asset to documents
      await new File(path).writeAsBytes(bytes,flush: true);
    }
    _database = await openDatabase(
      path,
    );
  } catch (e) {
    e.toString();
  }

0 个答案:

没有答案