public Manager loadManager() throws IOException, ClassNotFoundException { try { String workingDir = System.getProperty("user.dir"); FileInputStream fin = new FileInputStream(workingDir + "\\Manager.ser"); ObjectInputStream oin = new ObjectInputStream(fin); Manager m = (Manager) oin.readObject(); if (m != null) return m; else return new Manager(new Warehouse()); } catch (IOException e) { System.out.println("\nerror loading file!\n"); return new Manager(new Warehouse()); } }
// Deserialize properly private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); setState(0); // reset to unlocked state }