Skip to content

Instantly share code, notes, and snippets.

@mrWinston
Last active October 21, 2015 15:10
Show Gist options
  • Save mrWinston/f59c16183fa5801fec4a to your computer and use it in GitHub Desktop.
Save mrWinston/f59c16183fa5801fec4a to your computer and use it in GitHub Desktop.
Java Deserializing from File #java #serialization #file #stream
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details.
*/
try{
FileInputStream fileIn = new FileInputStream("object.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
Object o = (Object) in.readObject();
in.close();
fileIn.close();
}catch(IOException ioe){
throw new RuntimeException("Error while loading Object!", ioe);
}catch(ClassNotFoundException cnfe){
throw new RuntimeException("Error while loading Object!", cnfe);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment