This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert byte array to string array ?

 
chetan dhumane
Ranch Hand
Posts: 641
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am receiving byte array from client I need it to convert it into String array(Not in string).

Thanks in advance.
 
Campbell Ritchie
Sheriff
Posts: 51419
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't understand the question. I presume you have looked at the String constructors and not found anything suitable?

How are you going to split the byte[]? Have you got some sort of marker in it for when you divide to form a new String?
 
chetan dhumane
Ranch Hand
Posts: 641
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it necessary to put a marker in between.
I want to pass string array (which is converted to byte array) from client side and I want to convert it back to string array on server side.
 
Campbell Ritchie
Sheriff
Posts: 51419
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean to serialise it with a ByteArrayInputStream or a ByteArrayOutputStream?
 
chetan dhumane
Ranch Hand
Posts: 641
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From client side I am sending string array which by default get converted into byte array(client is in J2ME).

On server side I receive the data in byte array format.
I need to convert it back into original string array.(Server runs on Tomcat using Servlets doPost method)

Thanks in advance.

 
Campbell Ritchie
Sheriff
Posts: 51419
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ByteArrayInputStream and ByteArrayOutputStream? I presume you have it serialised from one end, then you have to deserialise it from the other end.
 
chetan dhumane
Ranch Hand
Posts: 641
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use this code in servlets doPost method



When I print text I get similar text which is sent by the client.
What changes shall I do to work it according to my need ?
 
Campbell Ritchie
Sheriff
Posts: 51419
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. It doesn't say anything in your code about byte[].

But this is no longer a beginner's question. Moving.
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without knowing how the String[] is converted into a byte[] in the first place, it's impossible to know how to convert it back. Was serialization used? Was the result of getBytes() of each element appended into one large byte array?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic