pdf转base64

public static String pdfToBase64() {
InputStream is = null;
ByteArrayOutputStream os = null;
String dUrlData="";
byte[] buff = new byte[1024];
int len = 0;
try {
is = new FileInputStream(new File("C:\\Users\\Administrator\\Desktop\\文档\\接口文档-修改版.pdf"));
os = new ByteArrayOutputStream();
while ((len = is.read(buff)) != -1) {
os.write(buff, 0, len);
}
os.flush();
os.toByteArray();
dUrlData = Base64.getEncoder().encodeToString(os.toByteArray());
} catch (IOException e) {
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {}
}
if (os != null) {
try {
os.close();
} catch (IOException e) {}
}
}
return dUrlData;
}
posted @ 2020-12-15 09:32  scwyfy  阅读(3543)  评论(0编辑  收藏  举报