Solarin
asked on
how to convert an object to into a byte
well, I've an object of type MyClass. what I want to do is to convert such object in byte or byte[] so that I can send it through a stream.
Any suggests??
Any suggests??
use ObjectOutputStream.writeOb ject()
This should tell you all you need to know:
http://java.sun.com/docs/books/tutorial/essential/io/serializing.html
http://java.sun.com/docs/books/tutorial/essential/io/serializing.html
ASKER
ok, the problem is quite different.
i've a DatagramPacket(byte[]...); and i've to put the byte value of the object in that field. it's nothing to do with streams.. :(
i've a DatagramPacket(byte[]...);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>toBytesArray
should have been
>>toByteArray
should have been
>>toByteArray
implements java.io.Serializable in MyClass
and user ObjectOutputStream to send it
and user ObjectOutputStream to send it
> implements java.io.Serializable in MyClass
> and user ObjectOutputStream to send it
Please don't repeat things that have already been said...
> and user ObjectOutputStream to send it
Please don't repeat things that have already been said...
Try:
byte arr[] = MyClassObject.toString ().getBytes () ;
Then make a DatagramPacket with this byte array.
Mayank.
byte arr[] = MyClassObject.toString ().getBytes () ;
Then make a DatagramPacket with this byte array.
Mayank.
How about rating it now?
Solarin:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept CEHJ's comment as answer.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
TimYates
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Accept CEHJ's comment as answer.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
TimYates
EE Cleanup Volunteer
:-)