Serialize an Object to a File with Java

On March 29, 2013, in Java, Programming, by LuCuS

Serialize an object to a file with Java.

	public static void serializeObject (Object object, String fileName)
    	try {
			ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName));
		} catch (FileNotFoundException e) {
		} catch (IOException e) {

And to test it…

	public static void main(String[] args) {
		MyObject myObject = new MyObject();
		serializeObject(myObject, "C:\\path\\to\\my\\file.dat");

Thank you for your interest in my site. If you find the information provided on this site useful, please consider making a donation to help continue development!

PayPal will open in a new tab.

Related Posts

Tagged with:  

Leave a Reply