Base64 encode data: Difference between revisions

Content added Content deleted
Line 1,192: Line 1,192:
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
String encodeFile(String path) throws IOException {
byte[] encodeFile(String path) throws IOException {
try (FileInputStream stream = new FileInputStream(path)) {
try (FileInputStream stream = new FileInputStream(path)) {
byte[] bytes = stream.readAllBytes();
byte[] bytes = stream.readAllBytes();
return Base64.getEncoder().encodeToString(bytes);
return Base64.getEncoder().encode(bytes);
}
}
}
}