1,105,556 Community Members

Contert byte into char

Member Avatar
kgkamaraj
Newbie Poster
19 posts since Jan 2010
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

HI,
Can any one know how to convert byte array into char array.

For example :

byte buf[]=teststr.getBytes();

Note:
buf is byte array. I need to convert this into char array.

Member Avatar
masijade
Industrious Poster
4,165 posts since Feb 2006
Reputation Points: 1,351 [?]
Q&As Helped to Solve: 510 [?]
Skill Endorsements: 22 [?]
Team Colleague
Featured
 
1
 

Why use getBytes? Why don't you use toCharArray? In any case, the easiest way (although not necessarily the most effecient) is to do new String(byte[]).toCharArray() .

Member Avatar
kgkamaraj
Newbie Poster
19 posts since Jan 2010
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

HI,
I am retriveing Vector values using getBytes.

// Her teststr is Vector..... Using toCharArray() i cant retrive these values...... So any other option is there......
For example :

byte buf[]=teststr.getBytes();

Note:
buf is byte array. I need to convert this into char array.

Member Avatar
masijade
Industrious Poster
4,165 posts since Feb 2006
Reputation Points: 1,351 [?]
Q&As Helped to Solve: 510 [?]
Skill Endorsements: 22 [?]
Team Colleague
Featured
 
0
 

What? What are you talking about? If you need these "bytes" as "chars" then do new String -> toCharArray There is no reason you cannot do that, unless those "bytes" do not represent characters (i.e. a String) and so "converting" them to chars would be pointless anyway.

I still have no idea what you mean by "Her teststr is Vector". Are you saying that this "byte buffer" is a serialised Vector object maybe? In which case this "conversion" is less than pointless anyway.

Member Avatar
kgkamaraj
Newbie Poster
19 posts since Jan 2010
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,
I got the output for my project .... .... masijade thanks for your information friend......

Question Answered as of 4 Years Ago by masijade
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article