Skip to content

Instantly share code, notes, and snippets.

@mrWinston
Last active October 21, 2015 15:10
Show Gist options
  • Save mrWinston/de47fc2993078bdbc79a to your computer and use it in GitHub Desktop.
Save mrWinston/de47fc2993078bdbc79a to your computer and use it in GitHub Desktop.
Java Serializing Object to File #java #serialization #file #stream #writing
/* 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{
Object o = new Object();
FileOutputStream fileOut = new FileOutputStream("object.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(o);
out.close();
fileOut.close();
System.out.printf("Serialized data is saved");
}catch(IOException ioe){
throw new RuntimeException("Could not save Object to file", ioe);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment