Last active
April 11, 2023 16:04
-
-
Save marcosbarker/f7b9149e4be6fb7ff1333d8bc7161e09 to your computer and use it in GitHub Desktop.
Codifica PDF em Base64 puro texto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Base64; | |
| import java.io.File; | |
| import java.nio.file.Files; | |
| import java.nio.file.Paths; | |
| import java.nio.file.StandardOpenOption; | |
| String filePath = "pdfTeste.pdf"; | |
| File file = new File(filePath); | |
| byte[] bytes = Files.readAllBytes(file.toPath()); | |
| String encodedFile = Base64.getEncoder().encodeToString(bytes); | |
| String outputFilePath = "base64purinhoPurinho.txt"; | |
| Files.write(Paths.get(outputFilePath), encodedFile.getBytes(), StandardOpenOption.CREATE); | |
| return encodeFile |
Author
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Codigo esta como "script", caso queira rodar em projeto, colocar o codigo da linha 7-15 dentro da classe main de um porojeto JAVA. Adicionar
System.out.println(encodedFile)em alternativa a linha 15 para que o base64 seja printado no console de saida.Projeto JAVA CodificaPDF-Base64