如何将下载的 PDF 文件保存为从 Rest WS 获取的 byte[] 数组
How to save a PDF file downloaded as byte[] array obtained from a Rest WS
我正在尝试保存之前从 REST WS 中作为 byte[] 数组获得的 PDF 文件。
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"
保存到Internal Storage时,没有root权限是看不到文件的,如果要查看,可以使用 adb
工具(由[=26签名的应用程序) =]调试)
adb shell
run-as packagename
cd /data/data/packagename
cd cache
ls
然后你可以看到 downloadfile.pdf
或者您可以将它保存到 External storage,然后您可以在您的设备文件管理器中找到它:
//"/storage/emulated/0/Android/data/packagename/files/downloadfile.pdf"
string path = Android.App.Application.Context.GetExternalFilesDir(null).ToString();
我正在尝试保存之前从 REST WS 中作为 byte[] 数组获得的 PDF 文件。
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"
保存到Internal Storage时,没有root权限是看不到文件的,如果要查看,可以使用 adb
工具(由[=26签名的应用程序) =]调试)
adb shell
run-as packagename
cd /data/data/packagename
cd cache
ls
然后你可以看到 downloadfile.pdf
或者您可以将它保存到 External storage,然后您可以在您的设备文件管理器中找到它:
//"/storage/emulated/0/Android/data/packagename/files/downloadfile.pdf"
string path = Android.App.Application.Context.GetExternalFilesDir(null).ToString();