programming-examples/java/XML/Serialise object to file.java
2019-11-15 12:59:38 +01:00

20 lines
494 B
Java

Serialise object to file
package com.ack.j2se.io;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class SerialiseObjectToFile {
public static void main( String[] args ) throws IOException {
String str = new String( "save me!" );
FileOutputStream fos = new FileOutputStream( "thefile.obj" );
ObjectOutputStream oos = new ObjectOutputStream( fos );
oos.writeObject( str );
oos.close();
}
}