base64转换成pdf在页面显示

byte[] bytes = base64String;  //把base64字符串转成byte数组
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(bytes); //把byte写进输出流里
if(baos!= null){
                httpServletResponse.setContentType("application/pdf");
                httpServletResponse.setContentLength(baos.size());
                httpServletResponse.setHeader("Expires", "0");
                httpServletResponse.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
                httpServletResponse.setHeader("Pragma", "public");
                javax.servlet.ServletOutputStream sos = httpServletResponse.getOutputStream();
                baos.writeTo(sos); //byte输出流写入servlet输出流
                sos.flush();
                sos.close();
                baos.close();
            }

你可能感兴趣的:(java)