프로그래밍/안드로이드
안드로이드 (JAVA) 에서 한글(EUC-KR 또는 UTF-8)을 자동 판단 하는 방법~
야로레
2017. 10. 12. 19:11
SMI 자막 파일 로드할때 인코딩때문에 애먹었는데 이걸로 해결 .
외부로 부터 전달받은 한글문자열이 EUC-KR인지 UTF-8인지 판단이 필요할때
사용될수 있는 소스 입니다.
해당 소스는 자동으로 LocalString으로 변경해 줍니다.
public static String LocalString( byte[] b)
{
try {
CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
try {
CharBuffer r = decoder.decode( ByteBuffer.wrap( b));
return r.toString();
} catch (CharacterCodingException e) {
return new String( b, "EUC-KR");
}
} catch (UnsupportedEncodingException e1) {
Log.d("Unity", e1.getMessage());
}
return null;
}
출처: http://symlink.tistory.com/20 [날개를 펴다]