package pbt.iotest;


import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/** 
 * WriteObjects, permet l'écriture d'un objet
 * de type {@link MyObject} dans un fichier "myobject.data"
 *  
 * @author pit
 */
public class WriteObjects {

	
	public static void main(String[] args) {
		final String FILENAME = "myobject.data" ;
		MyObject mo = new MyObject("Ma jolie description ") ;
		Integer i = new Integer(42) ;
		int j = 23 ; 
		ObjectOutputStream ois ; 
		
		try {
			System.out.println("Ouverture du fichier " + 
					FILENAME + " en écriture");
			ois = new ObjectOutputStream(
					new FileOutputStream(FILENAME)) ;
			System.out.println("Écriture de l'objet\n\t" + mo );
			ois.writeObject(mo) ; 
			System.out.println("Écriture de l'Integer " + i);
			ois.writeObject(i) ; 
			System.out.println("Écriture de l'int " + j);
			ois.writeInt(j) ; 
			ois.close(); 
		} catch (IOException ioe) {
			System.err.println("Problème d'E/S ");
			ioe.printStackTrace() ; 
		}

	}

}
