This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Converting an Array with any datatype  to byte array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Converting an Array with any datatype  to byte array" Watch "Converting an Array with any datatype  to byte array" New topic
Author

Converting an Array with any datatype to byte array

Aravind M
Greenhorn

Joined: Dec 18, 2007
Posts: 4
Hi Folks,

I have an array with different datatypes and I need to convert this array into a byte array and use it and again revert back to the original. how do I do that. Any suggestions are welcome.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
That is a job for object serialization, just write the array to an ObjectOutputStream to a ByteArrayOutputStream then use the toByteArray() method. All the little details are taken care of automatically and it is surprisingly fast.

Bill
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"Aravind",
Please check your private messages.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Yelamuri Chandu
Greenhorn

Joined: Jan 08, 2008
Posts: 15
check here some sample cofe
ByteArrayOutputStream bs = new ByteArrayOutputStream()
bs.write(.. .. ..);


byte [] bArr = bs .toByteArray();

Again you can create ByteArrayOutputStream with the above byte array.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"Aravind M",

Please check your private messages.
Abhishek Chattopadhyay
Greenhorn

Joined: Jan 10, 2008
Posts: 4
Can someone elaborate on the above given example how does it work ?
thanks in advance. :roll:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting an Array with any datatype to byte array
 
Similar Threads
byte array to inputstream
InputStream into byte array
About creating string from Base64 encoded byte array and then invoking getBytes...
converting byte array to pdf
byte[] to blob