|
|
@ -0,0 +1,40 @@ |
|
|
|
package objetoSerializable; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.ObjectOutputStream; |
|
|
|
import java.util.Iterator; |
|
|
|
|
|
|
|
public class Ejercicio8 { |
|
|
|
private static FileOutputStream fileout; |
|
|
|
private static Persona persona; |
|
|
|
private static ObjectOutputStream dataOs; |
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException { |
|
|
|
|
|
|
|
File fichero = new File("/home/michael/Desktop/Fichero.txt"); |
|
|
|
fileout = new FileOutputStream(fichero); |
|
|
|
dataOs = new ObjectOutputStream(fileout); |
|
|
|
inicializarDatos(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void inicializarDatos() throws IOException { |
|
|
|
String[] nombres= {"Juan","Pepe","Manolo","Erom"}; |
|
|
|
int[] edades= {18,20,56,78}; |
|
|
|
for (int i = 0; i < edades.length; i++) { |
|
|
|
persona = new Persona(nombres[i], edades[i]); |
|
|
|
dataOs.writeObject(persona); |
|
|
|
} |
|
|
|
|
|
|
|
fileout.close(); |
|
|
|
dataOs.close(); |
|
|
|
|
|
|
|
System.out.println("Se ha creado los datos y guardado en el archivo"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |