Noticias
: Realizada migración del foro, si tienen
problemas
con alguna imagen reportar al administrador
Inicio
Ayuda
Calendario
Ingresar
Registrarse
Bienvenido(a),
Visitante
. Por favor,
ingresa
o
regístrate
.
¿Perdiste tu
email de activación?
Abril 25, 2024, 10:01:33
1 Hora
1 Día
1 Semana
1 Mes
Siempre
Ingresar con nombre de usuario, contraseña y duración de la sesión
FOROS DE INFORMATICA
>
Programación
>
Java
>
Programa java interfaces
Páginas: [
1
]
« anterior
próximo »
Imprimir
Autor
Tema: Programa java interfaces (Leído 2455 veces)
vvtc
Nuevo
Karma:
0
Desconectado
Mensajes: 3
Programa java interfaces
«
:
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
« anterior
próximo »
Ir a:
Por favor selecciona un destino:
-----------------------------
General
-----------------------------
=> Spam
=> Noticias
=> Proteste Ya
=> Sugerencias
=> Opinamos sobre tu sitio
=> Presentaciones
-----------------------------
Diseño web
-----------------------------
=> Diseño gráfico
=> CSS
=> HTML
=> Editores web
=> Flash y ActionScript
=> Accesibilidad
-----------------------------
Programación
-----------------------------
=> .NET
=> Java
=> Php
=> Javascript
=> AJAX
=> Otros
-----------------------------
Bases de datos
-----------------------------
=> Sql Server
=> Oracle
=> MySql
=> Otros
-----------------------------
Administración de sistemas
-----------------------------
=> Alerta Virus
===> Analizamos su log de Hijackthis
=> Redes y seguridad
=> Sistemas Operativos
===> Windows
===> Linux
=> Servidores web
=> HardWare
=> Hosting
=> Dominios
-----------------------------
Negocios y ofertas
-----------------------------
=> Negocios electrónicos
=> Programadores
=> Ofertas de empleo
=> Proyectos
=> Posicionamiento Web
-----------------------------
Varios
-----------------------------
=> Ayuda general
===> Normas del foro
=> Software general
=> Descargas
===> Utilidades
===> Seguridad
===> Drivers
===> Tutoriales
===> Otros
=> Video Juegos
===> Trucos, Cheats y Hacks, etc
===> Servidores
=> Video y audio
=> Dispositivos Móviles
=> Curiosidades
Cargando...