MainActivity.java 文件源码

java
阅读 40 收藏 0 点赞 0 评论 0

项目:LoggingInterceptor 作者:
private void downloadFile(ResponseBody body) throws IOException {
    int count;
    byte data[] = new byte[1024 * 4];
    InputStream bis = new BufferedInputStream(body.byteStream(), 1024 * 8);
    outputFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "file.zip");
    OutputStream output = new FileOutputStream(outputFile);
    while ((count = bis.read(data)) != -1) {
        output.write(data, 0, count);
    }

    output.flush();
    output.close();
    bis.close();

    Intent target = new Intent(Intent.ACTION_VIEW);
    target.setDataAndType(Uri.fromFile(outputFile), "application/pdf");
    target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

    Intent intent = Intent.createChooser(target, "Open File");
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号