• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.nio package for bytetocharconversion

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about the toCharBuffer method? What happens if you use that?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't get why you need to use java.nio...

 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic