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인지 등에 따라 계산하는 방식이
조금씩은 달라집니다.
'개발자 이야기 > 안드로이드' 카테고리의 다른 글
| [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 |
| [안드로이드] 입력한 URL의 HTML 문서 내용을 String으로 가져오기(Proxy 설정 포함) (0) | 2011/12/30 |
| 안드로이드 개발 교재(책) 추천 (4) | 2011/12/29 |



댓글을 달아 주세요