如何在android中将pdf文件从资产文件夹存储到存储卡

如何在android中将pdf文件从资产文件夹存储到存储卡,android,Android,嗨,朋友们 我的资产文件夹中有pdf文件,现在我想将该pdf文件存储到SD卡。我想在webview中显示pdf,有人能告诉我怎么做吗 感谢使用AssetManager获取pdf: AssetManager assetManager = getAssets(); InputStream inputStream = assetManager.open("your_pdf.pdf"); 然后你可以把它写在卡片上: File sdCard = Environment.getExternalStorag

嗨,朋友们 我的资产文件夹中有pdf文件,现在我想将该pdf文件存储到SD卡。我想在webview中显示pdf,有人能告诉我怎么做吗


感谢使用AssetManager获取pdf:

AssetManager assetManager = getAssets();
InputStream inputStream = assetManager.open("your_pdf.pdf");
然后你可以把它写在卡片上:

File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdcard.getAbsolutePath() + "/where/you/want/it");
dir.mkdirs();
File file = new File(dir, "your_pdf.pdf");
FileOutputStream f = new FileOutputStream(file);
并展示它

Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, "application/pdf");
startActivity(intent);

@benwilliams它不工作它的给定文件NotFoundException permisson被拒绝。您需要
来编写。尝试调用
String[]files=assetManager.list()
并遍历它,查看是否显示您的PDF。@Ben Williams,该错误已修复,但仍无法显示。我认为显示代码中存在问题。您能告诉我必须做什么吗?它以什么方式不显示?您能否直接从SD卡中取出已写入的文件,并检查其是否已正确写入?你的PDF有多大?@ben williams是的,我可以从SD卡中提取PDF大小非常小