◆ 무한한 가능성/& JAVA

JAVA - 한글 인코딩 변환 체크 한방에 끝내기

치로로 2016. 3. 13. 17:57


1번 방법


JAVA - 한글 인코딩 변환 체크 한방에 끝내기           

 

String word = "무궁화 꽃이 피었습니다.";

System.out.println("utf-8 -> euc-kr        : " + new String(word.getBytes("utf-8"), "euc-kr"));

System.out.println("utf-8 -> ksc5601       : " + new String(word.getBytes("utf-8"), "ksc5601"));

System.out.println("utf-8 -> x-windows-949 : " + new String(word.getBytes("utf-8"), "x-windows-949"));

System.out.println("utf-8 -> iso-8859-1    : " + new String(word.getBytes("utf-8"), "iso-8859-1"));

System.out.println("iso-8859-1 -> euc-kr        : " + new String(word.getBytes("iso-8859-1"), "euc-kr"));

System.out.println("iso-8859-1 -> ksc5601       : " + new String(word.getBytes("iso-8859-1"), "ksc5601"));

System.out.println("iso-8859-1 -> x-windows-949 : " + new String(word.getBytes("iso-8859-1"), "x-windows-949"));

System.out.println("iso-8859-1 -> utf-8         : " + new String(word.getBytes("iso-8859-1"), "utf-8"));

System.out.println("euc-kr -> utf-8         : " + new String(word.getBytes("euc-kr"), "utf-8"));

System.out.println("euc-kr -> ksc5601       : " + new String(word.getBytes("euc-kr"), "ksc5601"));

System.out.println("euc-kr -> x-windows-949 : " + new String(word.getBytes("euc-kr"), "x-windows-949"));

System.out.println("euc-kr -> iso-8859-1    : " + new String(word.getBytes("euc-kr"), "iso-8859-1"));

System.out.println("ksc5601 -> euc-kr        : " + new String(word.getBytes("ksc5601"), "euc-kr"));

System.out.println("ksc5601 -> utf-8         : " + new String(word.getBytes("ksc5601"), "utf-8"));

System.out.println("ksc5601 -> x-windows-949 : " + new String(word.getBytes("ksc5601"), "x-windows-949"));

System.out.println("ksc5601 -> iso-8859-1    : " + new String(word.getBytes("ksc5601"), "iso-8859-1"));

System.out.println("x-windows-949 -> euc-kr     : " + new String(word.getBytes("x-windows-949"), "euc-kr"));

System.out.println("x-windows-949 -> utf-8      : " + new String(word.getBytes("x-windows-949"), "utf-8"));

System.out.println("x-windows-949 -> ksc5601    : " + new String(word.getBytes("x-windows-949"), "ksc5601"));

System.out.println("x-windows-949 -> iso-8859-1 : " + new String(word.getBytes("x-windows-949"), "iso-8859-1"));

 

출처 - http://titis.tistory.com/entry/java-인코딩-변환-한방에-해결





2번 방법


String Encoding = 테스트로깨진텍스트;

try {

String toBinaryRaw = new String(Encoding.getBytes() );

System.out.println("Binary Raw Data:" + toBinaryRaw );

//ShowAllByte( toBinaryRaw );

String toISO_8859 = new String(Encoding.getBytes(),"ISO-8859-1");

System.out.println("ISO-8859-1 Encoding : " + toISO_8859 );

//ShowAllByte( toISO_8859 );

String toUtf_8 = new String(Encoding.getBytes(),"utf-8");

System.out.println("UTF-8 Encoding : " + toUtf_8);

//ShowAllByte( toUtf_8 );

String toEUCKR = new String(Encoding.getBytes(),"euc-kr");

System.out.println("toEUCKR Encoding : " + toEUCKR );

//ShowAllByte( toEUCKR );

String toUTF8_EUCKR = new String( Encoding.getBytes("utf-8"),"euc-kr");

System.out.println("toUTF8_EUCKR Encoding : " + toUTF8_EUCKR );

//ShowAllByte( toUTF8_EUCKR  );

String toksc5601 = new String(Encoding.getBytes(),"KSC5601");

System.out.println("KSC5601 Encoding : " + toksc5601);

//ShowAllByte( toksc5601 );

String toms949 = new String(Encoding.getBytes(),"ms949");

System.out.println("MS949 Encoding : " + toms949);

//ShowAllByte( toms949 );


} catch (UnsupportedEncodingException e) {

e.printStackTrace();



3번 방법


//-----------------------

String originalStr = 테스트로깨진텍스트; // 테스트

String [] charSet = {"utf-8","euc-kr","ksc5601","iso-8859-1","x-windows-949"};

  

for (int i=0; i<charSet.length; i++) {

 for (int j=0; j<charSet.length; j++) {

  try {

   System.out.println("[" + charSet[i] +"," + charSet[j] +"] = " + new String(originalStr.getBytes(charSet[i]), charSet[j]));

  } catch (UnsupportedEncodingException e) {

   e.printStackTrace();

  }

 }

}

//--------------------------