agregar objeto en archivo binario en java
Publicado por victor garay (1 intervención) el 29/04/2015 21:22:34
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:
mi correo es [email protected],.edu.pe [email protected]
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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){}
}
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();
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],.edu.pe [email protected]
Valora esta pregunta


0