As I read on some websites, you can not modify the object, but you can change the value of a Boolean variable. The point is that I do it in the following way and it does not show any error, but when I make the modification and print the object it does not change anything. Is it possible to modify it?
public void ExistMoto (String file, String NameMoto) {
try {
MotObjectOutputStream objectOS = new MotObjectOutputStream(new FileOutputStream(fichero,true));
ObjectInputStream objectIS = new ObjectInputStream(new FileInputStream(fichero));
Object ObjMotos = objectIS.readObject();
while (ObjMotos != null) {
if (ObjMotos instanceof Moto) {
String ObjNombre = (((Moto) ObjMotos).getNombre());
if (ObNombrej.equals(NombreMoto)) { //Comprobar nombre existe
((Moto) ObjMotos).setExiste(false);
objectOS.writeObject(ObjMotos);
objectIS.close();
}else {
}
ObjMotos = objectIS.readObject();
}
}
System.out.println("Se ha cambiado el estado");
objectIS.close();
}
}
Any help is welcome. Thanks in advance!