![](/img/trans.png)
[英]FileSystemException: Cannot open file, path = '/storage/0/emulated/myfolder/myfile.txt' (OS Error: No such file or directory, errno = 2)
[英]FileSystemException: Cannot open file, path = 'Directory: '/storage/emulated/0/Android/data/
我正在嘗試在我的設備上保存 pdf,但出現此錯誤
FileSystemException:無法打開文件,路徑 = '目錄:'/storage/emulated/0/Android/data/esofos.health/files'/test.pdf
這是生成文檔的函數
_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();
};
使用Directory
路徑屬性而不是類的字符串表示。 像這樣的東西:
File('${directory.path}/test.pdf').writeAsBytes(document.save());
檢查提供的代碼片段時,目錄路徑的類型轉換不正確。 我們要求您更改以下代碼以正確保存和打開 pdf 文件。
final path = directory!.path;
請參考以下文檔鏈接,
UG: https ://help.syncfusion.com/flutter/pdf/getting-started#save-and-open-a-pdf-document-in-mobile
注意:我為 Syncfusion 工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.