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

时间:2011-04-20 14:58:45

标签: android

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

由于

1 个答案:

答案 0 :(得分:-1)

使用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);