In this JavaIO Tutorial, we will serialize collection of Line class instances using ObjectOutputStream and its writeObject method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) { try { //Sample 012.10: Create Object Output stream FileOutputStream saveFile = new FileOutputStream("D:\\Temp2\\Lines.drw"); ObjectOutputStream objectStream = new ObjectOutputStream(saveFile); //Sample 012.11: Write Objects into the File objectStream.writeObject(lines); objectStream.flush(); objectStream.close(); //Sample 012.12: Clear the Lines and Repaint lines.clear(); repaint(); JOptionPane.showMessageDialog(this, "Saved to C->Temp2->Lines.drw"); } catch(FileNotFoundException ex) { System.out.println(ex); } catch(IOException ex) { System.out.println(ex); } catch(Exception ex) { System.out.println(ex); } } |
- JavaIO Serialization | Collect Line Objects
- JavaIO Serialization | DeSerialize via ObjectInputStream
Categories: Java-Tube