public String getStringFromByte( byte[] byteInput )
{
StringBuffer sb = new StringBuffer();
for( int i=0; i<byteInput.length; i++ )
{
// Processing Korean
if( ( byteInput[i] & 0x80 ) == 0x80)
{
byte[] byteKorean = new byte[2];
byteKorean[0] = byteInput[i];
byteKorean[1] = byteInput[i++];
sb.append( new String( byteKorean ) );
}
else if( (byteInput[i] & 0xFF) == 0 )
{
}
else
{
sb.append( (char)byteInput[i] );
}
}
return sb.toString();
}
그리고 Byte[] 배열로부터 숫자값을 가져오는 것은 다음과 같이 할 수 있습니다.
DataInputStream in = new DataInputStream ( new FileInputStream( strFilePath ) );
if ( in != null )
{
int channelListVersion = in.readByte() & 0xFF;
int channelAntennaMode = in.readByte() & 0xFF;
int channelCount = ((in.readByte()) | (in.readByte() << 8)) & 0xFFFF;
}
물론, 이 바이너리 파일의 Endian 방식이 BigEndian인지, LittleEndian인지 등에 따라 계산하는 방식이
조금씩은 달라집니다.
'개발자 이야기 > 안드로이드' 카테고리의 다른 글
| [안드로이드] 특정 어플리케이션이 설치 또는 제거되는 이벤트 획득하기 (0) | 2012/03/06 |
|---|---|
| [안드로이드] 특정 패키지의 설치 여부를 판단하기 (0) | 2012/03/06 |
| [Java] Byte[] 배열로부터 String 가져오기(한글 등) 및 Byte[] 배열로부터 숫자값 읽어오기 (0) | 2012/02/03 |
| 윈도우즈용 Cygwin에서 경로(Path) 추가 방법 (0) | 2012/01/16 |
| [안드로이드] XML에서 각 단위(px, dip, sp 등)들의 의미 (0) | 2012/01/13 |
| [안드로이드 / OpenGL] 마치 2D 좌표계인 것처럼 그림 그리기 (0) | 2012/01/02 |



댓글을 달아 주세요