Create a Serialized Output File
From Java Example Source Code
Contents |
[edit] Overview - Create a Serialized Output File
This Java example shows how to create a serialized output file.
[edit] Java Source Code
- Package: com.bruceeckel
- File: FreezeAlien.java
package com.bruceeckel; //: c12:FreezeAlien.java //Create a serialized output file. //{Clean: X.file} //From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002 //www.BruceEckel.com. See copyright notice in CopyRight.txt. // modified by Code Panda, from http://java.exampleshow.com import java.io.FileOutputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.Serializable; import java.io.File; public class FreezeAlien { // Throw exceptions to console: public static void main(String[] args) throws Exception { String path = "C:\\exampleshow"; File dir = new File(path); dir.mkdirs(); ObjectOutput out = new ObjectOutputStream( new FileOutputStream(path+"\\alien.dat")); Alien zorcon = new Alien(); out.writeObject(zorcon); System.out.println("OK! See the file alien.dat in the folder C:\\exampleshow"); } } // /:~ class Alien implements Serializable { } // /:~
[edit] What Result You Can Get
Run the program, you will get:
OK! See the file alien.dat in the folder C:\exampleshow
[edit] Required External Library for this Java Example
Need nothing.
[edit] How to Run this Java Example Program
We recommend running this Java example program with Eclipse.
For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.
It's fairly easy.
[edit] Question & Answer
Any question?
Click edit and post your question or answer here.
