Javaã§æååã®æåã³ã¼ããå¤æãã
String eucjpStr = new String("å¤æãããæåå".getBytes("EUC_JP"), "EUC_JP");
ãã®ä¾ã®å ´åECU-JP
ã«å¤æãã¾ããå¤æãããæååã®æåã³ã¼ãã¯ãUTF-8ã§ãShift_JISã§ãä½ã§ãè¯ãã§ãã
ãã£ãããã ãã®äºãªãã ãã©ãæ¤ç´¢ãã¦ãå
¨ç¶ããã ãã®äºãè¦ã¤ãããªãã¦ãç¡é§ã«æéè²»ããã¡ãã£ã¦ãã«ãã¨ãªã£ã¦æ¸ããã
æç´
æå®ããã æåã»ãã ã使ç¨ãã¦ãã® String ããã¤ãã·ã¼ã±ã³ã¹ã«ç¬¦å·åããçµæãæ°è¦ãã¤ãé åã«æ ¼ç´ãã¾ãã
http://java.sun.com/javase/ja/6/docs/ja/api/java/lang/String.html#getBytes(java.nio.charset.Charset)
æå®ããã æåã»ãã ã使ç¨ãã¦ãæå®ããããã¤ãé åã復å·åãããã¨ã«ãã£ã¦ãæ°ãã String ãæ§ç¯ãã¾ããæ°ãã String ã®é·ãã¯æåã»ããã«ãã£ã¦å¤åããããããã¤ãé åé·ã¨ä¸è´ããªããã¨ãããã¾ãã
http://java.sun.com/javase/ja/6/docs/ja/api/java/lang/String.html#String(byte[],%20java.lang.String)
ãªãã¨ãåããã«ããæ¥æ¬èªã§ãããªã®ã§ãæ®æ®µJavaãæ¸ãã¦ã人ãå®éã«æ¸ããã®ãè¦ã¦ç¢ºèªãããã¨ããJava æåã³ã¼ã å¤æãã¨ãã§æ¤ç´¢ããã®ã«ãå ¨ç¶åºã¦ããªãã¨ããããã¨ãgetBytes()ã«æ¸¡ãæåã³ã¼ãåãå¤æåã®ãæå®ã¨ãééã£ã¦ããã¼ã¸ããã£ãããã¨ã«ããã¡ãã£ã¨ã¤ã©ã¤ã©ãã¡ããã¾ããã
解説
getBytes()
ã¯æååããã¤ãé
åã«å¤æããããã¾ãJavaã®äºã¯åãããªããã©ãå
é¨æåã³ã¼ããä¾ãã°Unicodeã ã£ãã¨ããããæååãªãã©ã«ã¯*1ã©ã®æåã³ã¼ãã§æ¸ãã¦ãã¦ããgetBytes()
ã§æå®ããæåã³ã¼ãã«ã¨ã³ã³ã¼ããã¦ããã®ãã¤ãé
åã«ãã¦è¿ã£ã¦ãããå¤åã ãã©ãå¤é¨ããå
¥åãããæååãã¼ã¿ã§ãã£ã¦ããJavaã®ä¸çã«å
¥ã£ãæç¹*2ã§ãåãæ§ã«getBytes()
ã§ã¯å¤æãã¦å¾ããæåã³ã¼ãåãæå®ããããããªãã ãããã
ã§ããã®ãã¤ãé
åãStringã¯ã©ã¹ã®ã³ã³ã¹ãã©ã¯ã¿ã«æ¸¡ãã¨ããã®æåã³ã¼ããªæååã«ãªãã
getBytes("EUC_JP")
ã ã£ããããã¤ãé
åã¯EUC-JPã§ã¨ã³ã³ã¼ããããã¼ã¿ã1ãã¤ããã¤é
åã«å
¥ããã£ã¦äºãªã®ã§ããã®ã¾ã¾ãã£ã¤ããã°EUC-JPã®æååã«ãªãã¯ãã ãã©ãæããã¯å¿µã®ãã第2å¼æ°ã§æåã³ã¼ããæå®ãã¦ããã¨ç¡é£ã¨ããäºããªã
è£è¶³
次ã®å表ã¯ãJava SE 6 ã§ãµãã¼ãããã¦ããã¨ã³ã³ã¼ãã£ã³ã°ã»ããã示ãã¾ããæ°ãã java.nio API ã§ä½¿ç¨ãããæ£æºåã¯ãå¤ãã®å ´åãjava.io API ããã³ java.lang API ã§ä½¿ç¨ãããååã¨ã¯ç°ãªãã¾ãã
http://java.sun.com/javase/ja/6/docs/ja/technotes/guides/intl/encoding.doc.html
ãªããAPIã«ãã£ã¦ãæåã³ã¼ãåãã¡ãã£ã¨éãããããjava.nioã¨ããã®ããªãã ãè¯ãç¥ããªããã©ãStringã¯ã©ã¹ã¯java.lang.Stringãªã®ã§ãjava.langã®æ¹ã«ãªãã¯ãã
java.nio | java.lang |
EUC-JP | EUC_JP |
UTF-8 | UTF8 |
MySQLã¯utf-8ãããªãã¦utf8ã§ééãããããªã¨æã£ã¦ããã©ãJavaãããããããããPerlãuse utf8
ã£ã¦ã®ãããããã¨ã«ããæåã³ã¼ãåãã¡ãã£ã¨ééããããã§ãã
ä½è«
ãããããããJavaã§ã¯æååã®æåã³ã¼ããå¤æãã¦å¤æ°ã«å
¥ããã¿ãããªäºã¯ãæ®éãããªãã®ãããããªããä»åã¯mayaaã®ãã³ãã¬ã¼ãå
ã§ãã©ããã¦ã1ã¶ææåã³ã¼ããå¤æ´ãããæããã£ã¦ãè¦èã®çã§ããã¾ããã
Javaã¯ãã¾ãã¨ãããå
¨ç¶åãããªãã®ã§ãããééãã¨ããã£ãããæãã¦ããããã¨å©ããã¾ãã
*1:ã¤ã¾ãã½ã¼ã¹ã³ã¼ãã¯
*2:Stringãªãã¸ã§ã¯ãã«ãªã£ãæç¹