入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

android 打开pdf文件 从inputStream读取数据并保存为文件

创建时间:2015-07-20 投稿人: 浏览次数:401
/**
 * 打开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();
}

 

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像