elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


  Mostrar Temas
Páginas: [1]
1  Programación / Java / guardar y leer objetos en archivos binarios en: 17 Abril 2015, 04:57 am
Saludos. Guardo los datos de pacientes(n. de expediente, dni, apellidos, nombres, telefono y fotografia) en un archivo binario. el metodo de guardar lo realiza bien, cuando ejecuto la busqueda me muestra solo el ultimo paciente ingresado... aqui les dejo elcodigo del boton guardar y buscar respectivamente:

private void btcGuardarActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        Object nombreArchivo = archivo;
        System.out.println(nombreArchivo);
        try{
            ObjectOutputStream fileout = new ObjectOutputStream(new FileOutputStream((String) nombreArchivo));
            fileout.writeObject(txtNroExpediente.getText());
            fileout.writeObject(txtDni.getText());
            fileout.writeObject(txtApellidos.getText());
            fileout.writeObject(txtNombres.getText());
            fileout.writeObject(txtDireccion.getText());
            fileout.writeObject(txtTelefono.getText());
            fileout.writeObject(lblFoto.getIcon());
            JOptionPane.showMessageDialog(null, "Los datos del paciente se guardaron corecttamente...");
            if(fileout!=null){
                fileout.close();
            }
        }catch(IOException e){}
        desactivarTextFields();
        btcGuardar.setEnabled(false);
        btcNuevo.setEnabled(true);
        btcBuscar.setEnabled(false);
    }

 private void btcBuscarActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        Object nombreArchivo = archivo;
        try{
            try (ObjectInputStream filein = new ObjectInputStream(new FileInputStream((String) nombreArchivo))){
                Object expediente = filein.readObject();
            if (txtNroExpediente.getText().equals(expediente)){
                Object dni = filein.readObject();
                Object apellidos = filein.readObject();
                Object nombres = filein.readObject();
                Object direccion = filein.readObject();
                Object telefono = filein.readObject();
                Object foto = filein.readObject();
                txtNroExpediente.setText((String) expediente);
                txtDni.setText((String) dni);
                txtApellidos.setText((String) apellidos);
                txtNombres.setText((String) nombres);
                txtDireccion.setText((String) direccion);
                txtTelefono.setText((String) telefono);
                lblFoto.setIcon((Icon) foto);
            }
                if(filein!=null){
                    filein.close();
                }
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(JDPacientes.class.getName()).log(Level.SEVERE, null, ex);
            }
        }catch(IOException e){}   
    }

de antemano gracias por el apoyo.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines