好吧,我有一些pdf需要通过base64encoder转换为base64.
最后,我使用解码器转换回pdf格式,但我的内容丢失了.
我的代码:
byte[] input_file = Files.readAllBytes(Paths.get("C:\\user\\Desktop\\dir1\\dir2\\test3.pdf"));
byte[] encodedBytes = Base64.getEncoder().encode(input_file);
String pdfInBase64 = new String(encodedBytes);
String originalString = new String(Base64.getDecoder().decode(encodedBytes));
System.out.println("originalString : " + originalString);
FileOutputStream fos = new FileOutputStream("C:\\user\\Desktop\\dir1\\dir2\\newtest3.pdf");
fos.write(originalString.getBytes());
fos.flush();
fos.close();
Run Code Online (Sandbox Code Playgroud)
结果:
编码:https://pastebin.com/fnMACZzH
谢谢