aspose file tools*
The moose likes I/O and Streams and the fly likes How to convert byte array to string array ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to convert byte array to string array ?" Watch "How to convert byte array to string array ?" New topic
Author

How to convert byte array to string array ?

chetan dhumane
Ranch Hand

Joined: Jan 07, 2009
Posts: 629

I am receiving byte array from client I need it to convert it into String array(Not in string).

Thanks in advance.


http://www.androcid.com/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39869
    
  28
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

Joined: Jan 07, 2009
Posts: 629

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

Joined: Oct 13, 2005
Posts: 39869
    
  28
Do you mean to serialise it with a ByteArrayInputStream or a ByteArrayOutputStream?
chetan dhumane
Ranch Hand

Joined: Jan 07, 2009
Posts: 629

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

Joined: Oct 13, 2005
Posts: 39869
    
  28
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

Joined: Jan 07, 2009
Posts: 629

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

Joined: Oct 13, 2005
Posts: 39869
    
  28
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

Joined: Oct 27, 2005
Posts: 19762
    
  20

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?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to convert byte array to string array ?