HashMap Conversion

A

andrewzzz

Hi guys,
how do i convert an hash map into a byte array(being able to restore
this later , without losing data)?
thanks a lot!
bye
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

andrewzzz said:
how do i convert an hash map into a byte array(being able to restore
this later , without losing data)?

Serialization !

Arne
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

andrewzzz said:
can you send me link where to find out how?

private static byte[] serialize(Object o) throws IOException {
ByteArrayOutputStream ba = new ByteArrayOutputStream(1000);
ObjectOutputStream oba = new ObjectOutputStream(ba);
oba.writeObject(o);
return ba.toByteArray();
}

private static Object deserialize(byte[] b) throws IOException,
ClassNotFoundException {
ByteArrayInputStream ba = new ByteArrayInputStream(b);
ObjectInputStream oba = new ObjectInputStream(ba);
return oba.readObject();
}

All objects need to be serializable for this to work though !

Arne
 
A

andrewzzz

can you send me link where to find out how? private static byte[] serialize(Object o) throws IOException {
ByteArrayOutputStream ba = new ByteArrayOutputStream(1000);
ObjectOutputStream oba = new ObjectOutputStream(ba);
oba.writeObject(o);
return ba.toByteArray();
}

private static Object deserialize(byte[] b) throws IOException,
ClassNotFoundException {
ByteArrayInputStream ba = new ByteArrayInputStream(b);
ObjectInputStream oba = new ObjectInputStream(ba);
return oba.readObject();
}

All objects need to be serializable for this to work though !

Arne



thanks so much! I will try now!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top