-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncodingMain1.java
More file actions
39 lines (29 loc) · 1.24 KB
/
Copy pathEncodingMain1.java
File metadata and controls
39 lines (29 loc) · 1.24 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
package charset;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import static java.nio.charset.StandardCharsets.*;
public class EncodingMain1 {
private static final Charset EUC_KR = Charset.forName("EUC_KR");
private static final Charset MS_949 = Charset.forName("MS_949");
public static void main(String[] args) {
System.out.println("== ASCII 영문 처리 ==");
encoding("A", US_ASCII);
encoding("A", ISO_8859_1);
encoding("A", EUC_KR);
encoding("A", UTF_8);
encoding("A", UTF_16BE);
System.out.println("== 한글 지원 ==");
encoding("가", EUC_KR);
encoding("가", MS_949);
encoding("가", UTF_8);
encoding("가", UTF_16BE);
System.out.println("== 기본 문자 집합 ==");
byte[] bytes = "A".getBytes();
System.out.printf("%s -> [%s] 인코딩 -> %s %s byte\n", "A", Charset.defaultCharset(), Arrays.toString(bytes), bytes.length);
}
public static void encoding(String text, Charset charset){
byte[] bytes = text.getBytes(charset);
System.out.printf("%s -> [%s] 인코딩 -> %s %s byte\n", text, charset, Arrays.toString(bytes), bytes.length);
}
}