getBytes()¸¦ ÀÌ¿ëÇÑ ¿¹Á¦
GetBytesTest.java
public class GetBytesTest {
public static void main(String[] args) {
String str = new String("num\u00e9ro");
try {
byte[] def = str.getBytes();
byte[] utf = str.getBytes("UTF8");
// print out contents of byte arrays
for (int i = 0; i < def.length; i++) {
System.out.println("[" + i + "]:" + def[i]);
}
System.out.println("-----");
for (int i = 0; i < utf.length; i++) {
System.out.println("[" + i + "]:" + utf[i]);
}
System.out.println("-----");
// Reconstruct strings using byte arrays
String defstr = new String(def);
String utfstr = new String(utf, "UTF8");
System.out.println("default: " + defstr);
System.out.println("utf8: " + utfstr);
} catch (java.io.UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
C:\javaExample\String>javac GetBytesTest.java
C:\javaExample\String>java GetBytesTest
[0]:110
[1]:117
[2]:109
[3]:63
[4]:114
[5]:111
-----
[0]:110
[1]:117
[2]:109
[3]:-61
[4]:-87
[5]:114
[6]:111
-----
default: num?ro
utf8: num?ro
¹®ÀÚ¿¡ ÇØ´çÇÏ´Â ¹ÙÀÌÆ®Äڵ带 ¾Ë¾Æ³½´Ù.
jabookÀúÀÚ¸íÇÔ |
Á¦¸ñ:¼Ò¼³°°Àº¹Ì´ÏÄÚµå ÀÛ¼ºÀÚ:Àںϸâ¹ö ÇÑâÇå |