In this Java IO Tutorial, we will deserialize object written in a file. Here we will use ObjectInputStream and readObject.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
private void btnOpenActionPerformed(java.awt.event.ActionEvent evt) { try { //Sample 012.13: Create Object Input Stream FileInputStream openFile = new FileInputStream("D:\\Temp2\\Lines.drw"); ObjectInputStream objectStream = new ObjectInputStream(openFile); //Sample 012.14: Read Line Objects from the File lines = (ArrayList<Line>) objectStream.readObject(); repaint(); } catch(FileNotFoundException ex) { System.out.println(ex); } catch(IOException ex) { System.out.println(ex); } catch(Exception ex) { System.out.println(ex); } } |
Categories: Java-Tube