Win a copy of The Java Performance Companion this week in the Performance 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
Pie
Posts: 49447
63
  • 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
Pie
Posts: 49447
63
  • 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
Pie
Posts: 49447
63
  • 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
Pie
Posts: 49447
63
  • 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: 20552
57
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic