Sono giorni che mi sbatto su questo c...o di problema con la serializzazione.
Ho creato un metodo load() per caricare da file un vettore contenente gli oggetti (ovviamente implementatati con l'interfaccia Serializable) del mio programma.
Il problema è che non lo fa. Mi restituisce un vettore vuoto dandomi un errore di I/O.
Questi sono i metodi di caricamento e salvataggio:
public static Vector load(String filename) {
Vector vet=new Vector(1000);
try {
FileInputStream file = new FileInputStream(filename);
ObjectInputStream in = new ObjectInputStream(file);
vet=(Vector)in.readObject();
in.close();
}
catch (ClassNotFoundException e){System.out.println ("ERRORE");}
catch (FileNotFoundException e){System.out.println ("ERRORE");}
catch (IOException e){System.out.println ("ERRORE");}
return vet;
}
public static void save(Vector v,String filename){
try {
FileOutputStream file=new FileOutputStream(filename);
ObjectOutputStream out = new ObjectOutputStream(file);
out.writeObject (v);
file.close();
out.flush();
}
catch (FileNotFoundException e){System.out.println ("ERRORE");}
catch (IOException e){System.out.println ("ERRORE");}
}
VI PREGO AIUTATEMI!