简体   繁体   English

FileSystemException:无法打开文件,路径 = '目录:'/storage/emulated/0/Android/data/

[英]FileSystemException: Cannot open file, path = 'Directory: '/storage/emulated/0/Android/data/

I'm trying to save a pdf on my device , but i got this error我正在尝试在我的设备上保存 pdf,但出现此错误

FileSystemException: Cannot open file, path = 'Directory: '/storage/emulated/0/Android/data/esofos.health/files'/test.pdf FileSystemException:无法打开文件,路径 = '目录:'/storage/emulated/0/Android/data/esofos.health/files'/test.pdf

this is the function that generate the document这是生成文档的函数

_generatepdf() async {

//Get external storage directory
final directory = await getExternalStorageDirectory();
//Get directory path
final path = directory;
// Create a new PDF document.
final PdfDocument document = PdfDocument();
// Add a PDF page and draw text.
document.pages.add().graphics.drawString(
    'Hello World!', PdfStandardFont(PdfFontFamily.helvetica, 12),
    brush: PdfSolidBrush(PdfColor(0, 0, 0)),
    bounds: const Rect.fromLTWH(0, 0, 150, 20));

// Save the document.
print(path);
File('$path/test.pdf').writeAsBytes(document.save());
// Dispose the document.
document.dispose();

};

Use Directory path property not string representation of class.使用Directory 路径属性而不是类的字符串表示。 Something like this:像这样的东西:

File('${directory.path}/test.pdf').writeAsBytes(document.save());

When checking the provided code snippet, the directory path was not type casted properly.检查提供的代码片段时,目录路径的类型转换不正确。 We request you to change the below code to save and open the pdf file properly.我们要求您更改以下代码以正确保存和打开 pdf 文件。

final path = directory!.path;

Please refer to the below documentation link,请参考以下文档链接,

UG: https://help.syncfusion.com/flutter/pdf/getting-started#save-and-open-a-pdf-document-in-mobile UG: https ://help.syncfusion.com/flutter/pdf/getting-started#save-and-open-a-pdf-document-in-mobile

Note: I work for Syncfusion.注意:我为 Syncfusion 工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FileSystemException:无法打开文件,路径 = '/storage/0/emulated/myfolder/myfile.txt'(操作系统错误:没有这样的文件或目录,errno = 2) - FileSystemException: Cannot open file, path = '/storage/0/emulated/myfolder/myfile.txt' (OS Error: No such file or directory, errno = 2) 存储/模拟/ 0 /打开失败:ENOENT(没有这样的文件或目录)? - storage/emulated/0/ open faild:ENOENT (no such file or directory)? FileSystemException:无法打开文件,路径 = 'assets/busStops.txt'(操作系统错误:没有这样的文件或目录,errno = 2) - FileSystemException: Cannot open file, path = 'assets/busStops.txt' (OS Error: No such file or directory, errno = 2) Android设备上的file:/// storage / emulated / 0路径 - file:///storage/emulated/0 path on android device Android - 无法打开内容:file:///storage/emulated/0 - Android - Unable to open content: file:///storage/emulated/0 Android - java.io.FileNotFoundException: /storage/emulated/0/Notes/File.txt: open failed: ENOENT (No such file or directory) - Android - java.io.FileNotFoundException: /storage/emulated/0/Notes/File.txt: open failed: ENOENT (No such file or directory) FileNotFoundException:/storage/emulated/0/JsonParseTutorialCache:打开失败:ENOENT(没有这样的文件或目录) - FileNotFoundException: /storage/emulated/0/JsonParseTutorialCache: open failed: ENOENT (No such file or directory) /storage/emulated/0/Notes/(没有那个文件或目录)? - /storage/emulated/0/Notes/ (No such file or directory)? 访问存储在android中的/ storage / emulated / 0目录中的文件时出现FileNotFoundException - FileNotFoundException when accessing file stored at /storage/emulated/0 directory in android 无法播放路径中的视频 (/storage/emulated/0/Android/data/com...) - Could not play video in the path (/storage/emulated/0/Android/data/com…)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM