forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBase64Wrap.java
More file actions
30 lines (21 loc) · 825 Bytes
/
Base64Wrap.java
File metadata and controls
30 lines (21 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.zetcode;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class Base64Wrap {
public static void main(String[] args) throws IOException {
var src = "Golden eagle in the sky";
try (var os = Base64.getEncoder().wrap(new FileOutputStream("src/resources/base64.txt"))) {
os.write(src.getBytes(StandardCharsets.UTF_8));
}
try (var is = Base64.getDecoder().wrap(new FileInputStream("src/resources/base64.txt"))) {
int len;
byte[] bytes = new byte[256];
while ((len = is.read(bytes)) != -1) {
System.out.print(new String(bytes, 0, len, StandardCharsets.UTF_8));
}
}
}
}