-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathUnicodeTest.java
More file actions
41 lines (33 loc) · 1 KB
/
UnicodeTest.java
File metadata and controls
41 lines (33 loc) · 1 KB
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
31
32
33
34
35
36
37
38
39
40
41
package test.pkg;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.IOException;
public class UnicodeTest {
public static String echo(String input) {
return input;
}
public static byte[] echoBytes(byte[] input) {
return input.clone();
}
public static void main(String[] args) {
try {
runTest();
} catch (IOException e) {
e.printStackTrace();
// exit 1
System.exit(1);
}
}
public static void runTest() throws IOException {
byte[] allBytes = Files.readAllBytes(Paths.get("encoding_test.cp1252"));
String allString = new String(allBytes, "Cp1252");
String echoedString = echo(allString);
// print out the echoed string
System.out.println(echoedString);
byte[] echoedBytes = echoBytes(allBytes);
// print out the echoed bytes as hex
for (byte b : echoedBytes) {
System.out.printf("%02X ", b);
}
}
}