public void anadeArticulo() { try { ObjectOutputStream oos; MiObjectOutputStream moos; Articulo art = new Articulo( Integer.parseInt(campos[0].getText()), campos[1].getText(), Double.parseDouble(campos[2].getText()), Integer.parseInt(campos[3].getText())); if (FICHERO.exists()) { moos = new MiObjectOutputStream(new FileOutputStream(FICHERO, FICHERO.exists())); moos.writeObject(art); moos.close(); } else { oos = new ObjectOutputStream(new FileOutputStream(FICHERO, FICHERO.exists())); oos.writeObject(art); oos.close(); } } catch (IOException e) { } }
public boolean comprobarArticuloExistente(Articulo art) { boolean existe = false; if (FICHERO.exists()) { try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(FICHERO))) { while (true) { Articulo articuloActual = (Articulo) ois.readObject(); if (articuloActual.getId() == art.getId() && articuloActual.getNombre().equals(art.getNombre()) && articuloActual.getPrecio() == art.getPrecio() && articuloActual.getCantAlmacen() == art.getCantAlmacen()) { existe = true; } } } catch (ClassNotFoundException e) { } catch (EOFException e) { } catch (IOException e) { } } return existe; }