Ver Mensaje Individual
  #5 (permalink)  
Antiguo 08/08/2013, 22:10
Delta33
 
Fecha de Ingreso: agosto-2013
Mensajes: 6
Antigüedad: 10 años, 9 meses
Puntos: 0
Respuesta: Problema con la serializacion de objetos

Código Java:
Ver original
  1. public void guardarListaActores() {
  2.         try{
  3.             ObjectOutputStream flujoSalida=new ObjectOutputStream(new FileOutputStream("listaActores.obj"));
  4.             Integer nObjetos=new Integer(actores.length);
  5.             flujoSalida.writeObject(nObjetos);
  6.             for(Actor actor : actores){
  7.                 flujoSalida.writeObject(actor);
  8.             }
  9.             flujoSalida.close();
  10.         }
  11.         catch(IOException e){
  12.         }
  13.     }

Código Java:
Ver original
  1. public void cargarListaActores() throws ClassNotFoundException, IOException{
  2.         try{
  3.             ObjectInputStream flujoEntrada=new ObjectInputStream(new FileInputStream("listaActores.obj"));
  4.             int n=((Integer)flujoEntrada.readObject()).intValue();
  5.             for(int i=0 ; i<n ; i++){
  6.                 Actor actor=(Actor)flujoEntrada.readObject();
  7.                 agregarActor(actor);  //Clase que se encarga de la insercion del objeto en el vector
  8.             }
  9.             flujoEntrada.close();
  10.         }
  11.         catch(FileNotFoundException e){
  12.            
  13.         }
  14.         catch(IOException e){
  15.            
  16.         }
  17.        
  18.     }

De la misma manera hago con la lista de objetos Pelicula