xamarin - 如何将下载的 PDF 文件保存为从 Rest WS 获得的 byte[] 数组
问题描述
我试图将以前从 REST WS 获得的 PDF 文件保存为 byte[] 数组。
byte[] response = await caller.DownloadFile(url);
string documentPath = FileSystem.CacheDirectory;
string fileName = "downloadfile.pdf";
string path = Path.Combine(documentPath, fileName);
File.WriteAllBytes(path, response);
我的实际实现没有显示任何错误,但是当我在缓存文件夹中查找文件时,什么都没有,只有一个空文件夹。也尝试将文件放入FileSystem.AppDataDirectory
,Environment.GetFolderPath(Environment.SpecialFolder.Personal)
但任何文件夹中都没有文件
我错过了什么?
提前致谢。
解决方案
string documentPath = FileSystem.CacheDirectory;
string fileName = "downloadfile.pdf";
string path = Path.Combine(documentPath, fileName);
路径会喜欢
"/data/user/0/packagename/cache/downloadfile.pdf"
当你将它保存到内部存储时,你无法看到没有root权限的文件,如果你想查看它,你可以使用 adb
工具(Android Debug签名的应用程序)
adb shell
run-as packagename
cd /data/data/packagename
cd cache
ls
然后你可以看到downloadfile.pdf
或者您可以将其保存到外部存储,然后您可以在设备文件管理器中找到它:
//"/storage/emulated/0/Android/data/packagename/files/downloadfile.pdf"
string path = Android.App.Application.Context.GetExternalFilesDir(null).ToString();
推荐阅读
- ios - 在 iOS 中检测前台/后台代表的合适位置是什么?
- reactjs - 一旦我更新了 mobx 5,KonvaJs 示例就不起作用
- asp.net - oData v4 - 对相关一对多实体中的属性排序外部实体
- javascript - 在javascript中从数组中选择随机数量的元素
- python - 通过带参数的应用函数按计划运行作业
- angular - 如何在启用 IVY 的情况下调试 Angular 9 编译错误?
- python - 同名的类和函数
- kotlin - 如何在 Kotlin 伴随对象中设置线程安全的全局变量?
- ssas - Analysis Services 多维数据集层次结构总计
- regex - 无数的常规语言