FOROS DE INFORMATICA
Noticias: Realizada migración del foro, si tienen problemas con alguna imagen reportar al administrador
 
*
Bienvenido(a), Visitante. Por favor, ingresa o regístrate.
¿Perdiste tu email de activación?
Abril 25, 2024, 10:01:33


Ingresar con nombre de usuario, contraseña y duración de la sesión


Páginas: [1]
  Imprimir  
Autor Tema: Programa java interfaces  (Leído 2455 veces)
vvtc
Nuevo
*

Karma:0
Desconectado Desconectado

Mensajes: 3


« : Septiembre 01, 2013, 10:41:40 »

Actividad_7

package actividad_7;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;


/**
 *
 *
 */
public class Actividad_7 implements java.io.Serializable{
    
    //Se declaran todas las variables del objeto empleados (empl)
    private String nombre;
    private String apellidos;
    private String dni;
    private int telefono;
    private String direccion;
    private int edad;
    private String fecha;
    private String tipoEmple;
    private String puesto;
 private static String rutafichero="D:/Vane/VaneDAI/ACTIVIDADES_PROGRAMACION/UNIDAD7/vila_teissiere_vanesa_PROG07_Tarea/Actividad_7/datos/empleados.dat";
                                        
    //Se crean los métodos get y set de todas las variables

    public String getNombre() {
        return nombre;
    }

    public String getApellidos() {
        return apellidos;
    }

    public void setApellidos(String apellidos) {
        this.apellidos = apellidos;
    }

    public String getFecha() {
        return fecha;
    }

    public void setFecha(String fecha) {
        this.fecha = fecha;
    }

   /* public String getRutafichero() {
        return rutafichero;
    }

    public void setRutafichero(String rutafichero) {
        this.rutafichero = rutafichero;
    }*/

    public String getDni() {
        return dni;
    }

    public void setDni(String dni) {
        this.dni = dni;
    }

    public int getTelefono() {
        return telefono;
    }

    public void setTelefono(int telefono) {
        this.telefono = telefono;
    }

    public String getDireccion() {
        return direccion;
    }

    public void setDireccion(String direccion) {
        this.direccion = direccion;
    }

    public int getEdad() {
        return edad;
    }

    public void setEdad(int edad) {
        this.edad = edad;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }
    //Se crea el constructor por parámetros
    public Actividad_7( String nombre, String apellidos, String dni, int telefono,
            String direccion, int edad, String fecha, String tipoEmple, String puesto){
        this.nombre=nombre;
        this.apellidos=apellidos;
        this.dni=dni;
        this.telefono=telefono;
        this.direccion=direccion;
        this.edad=edad;
        this.fecha=fecha;
        this.tipoEmple=tipoEmple;
        this.puesto=puesto;
    }

    public String getPuesto() {
        return puesto;
    }

    public void setPuesto(String puesto) {
        this.puesto = puesto;
    }

    public String getTipoEmple() {
        return tipoEmple;
    }

    public void setTipoEmple(String tipoEmple) {
        this.tipoEmple = tipoEmple;
    }
    
    public static List AbrirFichero()throws IOException, ClassNotFoundException, FileNotFoundException{
    //Se crea el método AbrirFichero para crear el fichero empleados.dat o abrirlo en modo lectura si ya existe.
    //Recoge también los posibles errores medainte el try-catch  
        
        FileInputStream fichero=null;
        ObjectInputStream registro=null;                      
        List listEmple =new ArrayList();
        
            fichero=new FileInputStream(rutafichero);
            registro=new ObjectInputStream(fichero);

             //leemos el archivo de empleados.dat(fichero)con registro.readObjetc    
             listEmple=(List)registro.readObject();//Se hace casting porque sino los tipos son incompatbles      
             registro.close();
             fichero.close();
        
         return listEmple;
} //Fin metodo abrir fichero
    
    public static void GuardarFichero(List listEmple) throws IOException{
        FileOutputStream fichero1;
        ObjectOutputStream registro1;
        try {
            
            fichero1=new FileOutputStream(rutafichero);
            registro1= new ObjectOutputStream (fichero1);
            
            registro1.writeObject(listEmple);//Se vuelca sobre el fichero emplados.dat el contenido del array listEmple
            
            registro1.close();//Cierre registro
            fichero1.close();//Cierre fichero
            
            }
            catch (FileNotFoundException ex) {
                                        
            }
            catch (IOException ex) {
                
            }    
    }
    
    public static void   borrarFichero(){
            File archivo=new File (rutafichero);//Se crea un objeto archivo de tipo File y se le pasa la variable ruta fichero
            // (donde está almacenado el archivo que queremos borrar, en este caso Clientes.dat)
            archivo.delete();//Se utiliza el método delete para borrar el objeto archivo.
            
    }
    
}//fin clase
-------------------------------------------------------------------------------------------------------------------------------------
« Última modificación: Septiembre 01, 2013, 10:45:30 por vvtc » En línea
Páginas: [1]
  Imprimir  
 
Ir a:  

Impulsado por MySQL Impulsado por PHP Powered by SMF 1.1.13 | SMF © 2006-2009, Simple Machines LLC

XHTML 1.0 válido! CSS válido! Dilber MC Theme by HarzeM