Is it possible to use the new try-with-resources operator in Java 7 to simultaneously create both an ObjectOutputStream and an ObjectInputStream , and also clear the output stream before creating the input stream? Right now, I'm using the old style:
ObjectOutputStream ostream = null; ObjectInputStream istream = null; try { ostream = new ObjectOutputStream(this.socket.getOutputStream()); ostream.flush(); istream = new ObjectInputStream(this.socket.getInputStream()); // ... } catch (Exception e) { e.printStackTrace(); } finally { // Close the streams. }
I would like to know if there is a better way to create and clean up threads using the new style in Java 7. Thanks!
source share