• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.nio package for bytetocharconversion

 
medhaj hambi
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is there a way I can use java.nio package for byte to char array conversion ? Due to some technical reason, I have to write a code and have to use the package java.nio and I am not able to figure out a way to do that. It will be great if someone can suggest me or provide me a sample code snippet. Really appreciate your help !

Thanks
 
Campbell Ritchie
Marshal
Posts: 52531
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you have to use a “package”? Why are you being micro‑managed like that? Have you read the list of classes in that package? Have you seen that those classes have methods to create different kinds of buffer?
 
medhaj hambi
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I did, but not sure which method to use for ByteToChar conversion. Any pointers would be appreciated.
 
Campbell Ritchie
Marshal
Posts: 52531
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about the toCharBuffer method? What happens if you use that?
 
Winston Gutkowski
Bartender
Posts: 10571
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
medhaj hambi wrote:Is there a way I can use java.nio package for byte to char array conversion ? Due to some technical reason, I have to write a code and have to use the package java.nio and I am not able to figure out a way to do that. It will be great if someone can suggest me or provide me a sample code snippet. Really appreciate your help !

OK, well you can create a ByteBuffer with ByteBuffer.wrap(byte[]). After that, follow Campbell's advice.
If we simply hand you the code, you won't learn because you really need to try these things out for yourself.

It's also worth mentioning that byte→char conversion is rarely as simple as it sounds. If it's bog-standard 7-bit ASCII you should be fine, but there are any number of "codepages" out there (like Windows-1252), which may require specific mapping, so it's important to understand ALL the requirements before you start.

HIH

Winston
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't get why you need to use java.nio...

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!