Study/Java
[Class String] Encode/Decode Constructor, Method
momong'-'
2020. 7. 16. 12:31
Encoding (인코딩) Method
Modifier and Type | Method and Description |
byte[] | getByte() |
byte[] | getByte(Charset charset) |
byte[] | getByte(String charsetName) |
Decoding(디코딩) Method
Constructor and Description |
String(byte[] bytes) |
String(byte[] bytes, Charset charset) |
String(byte[] bytes, int offset, int length) |
String(byte[] bytes, int offset, int length, Charset charset)St |
String(byte[] bytes, int offset, int length, String charsetName) |
String(byte[] bytes, String charsetName) |
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import java.io.UnsupportedEncodingException;
public class StringTest {
public static void main(String[] args) throws UnsupportedEncodingException {
String str = "안녕하세요";
System.out.println("=======================");
System.out.println("인코딩 전: " + str);
System.out.println("=======================");
String encodingKo = new String (str.getBytes("KSC5601"), "8859_1");
System.out.println("인코딩: " + encodingKo);
System.out.println("=======================");
String decodingKo = new String (encodingKo.getBytes("8859_1"), "KSC5601");
System.out.println("디코딩: " + decodingKo);
}
}
|
cs |
=======================
인코딩 전: 안녕하세요
=======================
인코딩: ¾È³çÇϼ¼¿ä
=======================
디코딩: 안녕하세요
참고
더보기
"string", Java Platform SE 8, https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#getBytes-java.lang.String-