Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/05/2015, 10:46
vgaraysoft
 
Fecha de Ingreso: abril-2015
Mensajes: 3
Antigüedad: 9 años
Puntos: 0
Agregar objetos en un archivo binario en java

Saludos

Guardo los datos de los pacientes: numero de expediente, dni, apellidos, nombres, telefono, direccion y fotografia en un archivo binario, pero al parecer se sobreescribe el archivo, por eso cuando busco solo me muestra el ultimo ingresado, dejo aqui los codigos de guardar y buscar respectivament para que me puedan ayudar. gracias:

private void btcGuardarActionPerformed(java.awt.event.ActionEve nt 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){}
}

private void btcBuscarActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
Object nombreArchivo = archivo;
try{
try (ObjectInputStream filein = new ObjectInputStream(new FileInputStream((String) nombreArchivo))){
Object expediente = filein.readObject();
Object dni = filein.readObject();
Object apellidos = filein.readObject();
Object nombres = filein.readObject();
Object direccion = filein.readObject();
Object telefono = filein.readObject();
Object foto = filein.readObject();
if (txtNroExpediente.getText().equals(expediente)){
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){}
}
mi correo es [email protected] [email protected]