Created
June 7, 2017 14:49
-
-
Save gbonk/c3eb2522d4824f0867de669146afe86e to your computer and use it in GitHub Desktop.
example in java of how to serialize and de-serialize a hashtable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.ObjectInputStream; | |
import java.io.ObjectOutputStream; | |
import java.util.Hashtable; | |
public class StringInt { | |
public static void main(String[] args) { | |
Hashtable<String, Integer> ht = new Hashtable<String, Integer>(); | |
ht.put("Key", 1); | |
ht.put("Greg", 4); | |
try { | |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
ObjectOutputStream out = new ObjectOutputStream(bos); | |
out.writeObject(ht); | |
System.out.println(bos.toString()); | |
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); | |
ObjectInputStream in = new ObjectInputStream(bis); | |
Object object = in.readObject(); | |
out.close(); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This dumps out...