List of usage examples for java.io ObjectOutputStream writeObject
public final void writeObject(Object obj) throws IOException
From source file:Copy.java
public static void main(String args[]) throws Exception { String elements[] = { "Irish Setter", "Poodle", "English Setter", "Gordon Setter", "Pug" }; Set set = new HashSet(Arrays.asList(elements)); Set set2 = ((Set) ((HashSet) set).clone()); System.out.println(set2);/*from w ww .ja v a 2 s. c om*/ FileOutputStream fos = new FileOutputStream("set.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(set); oos.close(); FileInputStream fis = new FileInputStream("set.ser"); ObjectInputStream ois = new ObjectInputStream(fis); Set set3 = (Set) ois.readObject(); ois.close(); System.out.println(set3); }
From source file:SaveVector.java
public static void main(String args[]) throws Exception { String data[] = { "Java", "Source", "and", "Support", "." }; Vector v = new Vector(Arrays.asList(data)); ByteArrayOutputStream b = new ByteArrayOutputStream(); ObjectOutputStream o = new ObjectOutputStream(b); o.writeObject(v); o.close();/*from w w w . j a va 2 s . c o m*/ ByteArrayInputStream bb = new ByteArrayInputStream(b.toByteArray()); ObjectInputStream oo = new ObjectInputStream(bb); Vector v2 = (Vector) oo.readObject(); Enumeration e = v.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:shutdown.java
License:asdf
public static void main(String[] args) throws ClassNotFoundException, IOException { FileOutputStream fos = new FileOutputStream("objects.tmp"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject("asdf"); oos.flush();//from w w w . j a v a 2 s.co m fos.close(); FileInputStream fis = new FileInputStream("objects.tmp"); ObjectInputStream ois = new ObjectInputStream(fis); String t = (String) ois.readObject(); fis.close(); }
From source file:Main.java
public static void main(String[] args) { Card card = new Card(); try {//w w w . j a va2s . co m FileOutputStream out = new FileOutputStream("card.out"); ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(card); oos.flush(); oos.close(); } catch (Exception e) { System.out.println("Problem serializing: " + e); } }
From source file:SaveVector1.java
public static void main(String args[]) throws Exception { Vector v = new Vector(Arrays.asList(args)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(v); oos.close();/*from w w w .j a v a2s. c o m*/ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); Vector v2 = (Vector) ois.readObject(); Enumeration e = v.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Hashtable h = new Hashtable(); h.put("string", "AAA"); h.put("int", new Integer(26)); h.put("double", new Double(Math.PI)); FileOutputStream fileOut = new FileOutputStream("hashtable.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(h); FileInputStream fileIn = new FileInputStream("h.ser"); ObjectInputStream in = new ObjectInputStream(fileIn); Hashtable h = (Hashtable) in.readObject(); System.out.println(h.toString()); }
From source file:MainClass.java
public static void main(String[] a) throws Exception { List list = Arrays.asList(new String[] { "A", "B", "C", "D" }); FileOutputStream fos = new FileOutputStream("list.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(list); oos.close();//from ww w . ja va2 s. com FileInputStream fis = new FileInputStream("list.ser"); ObjectInputStream ois = new ObjectInputStream(fis); List anotherList = (List) ois.readObject(); ois.close(); System.out.println(anotherList); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { Vector v = new Vector(Arrays.asList("a", "b", "c")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(v); oos.close();// w w w . ja v a 2 s.com ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); Vector v2 = (Vector) ois.readObject(); Enumeration e = v.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:MainClass.java
public static void main(String[] a) throws Exception { String elements[] = { "A", "B", "C", "D", "E" }; Set set = new HashSet(Arrays.asList(elements)); FileOutputStream fos = new FileOutputStream("set.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(set); oos.close();//from w w w .j a va 2 s .c o m FileInputStream fis = new FileInputStream("set.ser"); ObjectInputStream ois = new ObjectInputStream(fis); Set anotherSet = (Set) ois.readObject(); ois.close(); System.out.println(anotherSet); }
From source file:Main.java
public static void main(String[] a) throws Exception { List list = Arrays.asList(new String[] { "A", "B", "C", "D" }); FileOutputStream fos = new FileOutputStream("list.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(list); oos.close();//from ww w . jav a 2 s. c om FileInputStream fis = new FileInputStream("list.ser"); ObjectInputStream ois = new ObjectInputStream(fis); List anotherList = (List) ois.readObject(); ois.close(); System.out.println(anotherList); }