android 打开pdf文件 从inputStream读取数据并保存为文件
/** * 打开pdf 文件,Get PDF file Intent。 * @param path 文件路径 * @return */ public static Intent getPdfFileIntent(String path) { Intent i = new Intent(Intent.ACTION_VIEW); i.addCategory(Intent.CATEGORY_DEFAULT); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromFile(new File(path)); i.setDataAndType(uri, "application/pdf"); return i; } /** * 从inputStream 读取数据 并保存为文件。 */ public static void inputStreamToFile(InputStream ins, File file) throws IOException { OutputStream os = new FileOutputStream(file); int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { os.write(buffer, 0, bytesRead); } os.close(); ins.close(); }
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: lodash的2个数组对象操作
- 下一篇: .Net后台调用前台js的两种方法