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;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM