filesystemexception:创建失败,路径='目录:'' (OS错误:仅读取文件系统,ERRNO = 30)

发布于 2025-02-06 16:07:54 字数 2218 浏览 1 评论 0原文

我正在收到错误作为未经手的异常:fileSystemexception:创建失败,path ='directory:''(OS错误:仅读取文件系统,errno = 30)当我尝试保存XLSX时文件。

代码:

class ExportPasswords {
  static exportUserEntries(List entries) async {
    final _psd = PasswordDecrypter();
    final _secureStorage = FlutterSecureStorage();

    //creating the xlsx
    var excel = Excel.createExcel();
    var fileBytes = excel.save();

    Sheet sheetObject = excel['pssswd_export'];
    CellStyle cellStyle = CellStyle(
        backgroundColorHex: "#1AFF1A",
        fontFamily: getFontFamily(FontFamily.Calibri));
    cellStyle.underline = Underline.Single;

    for (var entry in entries) {
      final _username = entry['data']['username'];
      final _name = entry['data']['name'];
      final _url = entry['data']['url'];
      final _hashedPassword = entry['data']['password'];
      final _randForKeyToStore = entry['data']['randForKeyToStore'];
      final _randForIV = entry['data']['randForIV'];
      final _masterPassword = await _secureStorage.read(key: 'masterPassword');

      final _decryptedEntryPassword = await _psd.getDecryptedPassword(
          _hashedPassword, _randForKeyToStore, _randForIV, _masterPassword);

      sheetObject.appendRow([_name, _username, _decryptedEntryPassword, _url]);
    }
    PermissionStatus permissionResult =
        await SimplePermissions.requestPermission(
            Permission.WriteExternalStorage);
    if (permissionResult == PermissionStatus.authorized) {
      Directory directory = await getApplicationDocumentsDirectory();
      // print(directory);
      new Directory(directory.path + '/').create(recursive: true).then((dir) {
        print(dir);
        File(join('$dir/pssswd_export'))
          ..createSync(recursive: true)
          ..writeAsBytesSync(fileBytes!);
      });
    }
  }
}

我已获得write_external_storage的许可。

I/SimplePermission( 7685): Requesting permission : android.permission.WRITE_EXTERNAL_STORAGE
I/SimplePermission( 7685): Requesting permission status : 3

在错误中,它显示为目录:'',但是当我打印目录值时,它将显示路径

I/flutter ( 7685): Directory: '/data/user/0/com.palsoham.pssswd.pssswd/app_flutter/'

I am receiving an error as Unhandled Exception: FileSystemException: Creation failed, path = 'Directory: '' (OS Error: Read-only file system, errno = 30) when I am trying to save a xlsx file.

Code:

class ExportPasswords {
  static exportUserEntries(List entries) async {
    final _psd = PasswordDecrypter();
    final _secureStorage = FlutterSecureStorage();

    //creating the xlsx
    var excel = Excel.createExcel();
    var fileBytes = excel.save();

    Sheet sheetObject = excel['pssswd_export'];
    CellStyle cellStyle = CellStyle(
        backgroundColorHex: "#1AFF1A",
        fontFamily: getFontFamily(FontFamily.Calibri));
    cellStyle.underline = Underline.Single;

    for (var entry in entries) {
      final _username = entry['data']['username'];
      final _name = entry['data']['name'];
      final _url = entry['data']['url'];
      final _hashedPassword = entry['data']['password'];
      final _randForKeyToStore = entry['data']['randForKeyToStore'];
      final _randForIV = entry['data']['randForIV'];
      final _masterPassword = await _secureStorage.read(key: 'masterPassword');

      final _decryptedEntryPassword = await _psd.getDecryptedPassword(
          _hashedPassword, _randForKeyToStore, _randForIV, _masterPassword);

      sheetObject.appendRow([_name, _username, _decryptedEntryPassword, _url]);
    }
    PermissionStatus permissionResult =
        await SimplePermissions.requestPermission(
            Permission.WriteExternalStorage);
    if (permissionResult == PermissionStatus.authorized) {
      Directory directory = await getApplicationDocumentsDirectory();
      // print(directory);
      new Directory(directory.path + '/').create(recursive: true).then((dir) {
        print(dir);
        File(join('$dir/pssswd_export'))
          ..createSync(recursive: true)
          ..writeAsBytesSync(fileBytes!);
      });
    }
  }
}

I have given the permission of WRITE_EXTERNAL_STORAGE.

I/SimplePermission( 7685): Requesting permission : android.permission.WRITE_EXTERNAL_STORAGE
I/SimplePermission( 7685): Requesting permission status : 3

In the error it is displayed as Directory : '', but when I am printing the directory value it is showing the path

I/flutter ( 7685): Directory: '/data/user/0/com.palsoham.pssswd.pssswd/app_flutter/'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

燕归巢 2025-02-13 16:07:54

请尝试从文件函数中更改路径,从'$/pssswd_export'dir.dir.path +/pssswd_export'

Please try changing your path in File function from '$dir/pssswd_export' to dir.path + /pssswd_export'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文