• Post Reply Bookmark Topic Watch Topic
  • New Topic

what use byte array?  RSS feed

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the following code


I have obtained a byte array. How can it be used to access a 16 bit integer value?
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It cannot.

The getBytes() method encodes the characters of the string in the "default encoding." The default encoding depends on the underlaying system's language and country settings. For example on Windows in a western locale it would be Windows-1252. It is a one-byte-per-char encoding that looks like this: http://www.microsoft.com/globaldev/reference/sbcs/1252.mspx

On other systems the character encoding would be different and the results different.

The 16-bit two-bytes-per-char representation that Java uses internally (as far as we can tell) can be obtained by passing a specific encoding to the method as a parameter, like this:
(note that using getBytes(String) requires you to be prepared to catch an exception--please see the API documentation for details)
[ February 20, 2006: Message edited by: Joni Salonen ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!