|
|
@ -3,27 +3,30 @@ package com.jesuspinar.miobjeto.serializable; |
|
|
|
import com.jesuspinar.miobjeto.serializable.controller.ObjReader; |
|
|
|
import com.jesuspinar.miobjeto.serializable.controller.ObjWriter; |
|
|
|
import com.jesuspinar.miobjeto.serializable.model.Person; |
|
|
|
import com.jesuspinar.miobjeto.serializable.model.People; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
public class Main { |
|
|
|
public static void main(String[] args) { |
|
|
|
Person person = new Person("Manolo", 32); |
|
|
|
Person person1 = new Person("Javier", 23); |
|
|
|
|
|
|
|
File file = new File("person.bin"); |
|
|
|
|
|
|
|
ObjWriter.write(person,file); |
|
|
|
ObjWriter.write(person1,file); |
|
|
|
//Create list |
|
|
|
People data = new People(); |
|
|
|
//Init list |
|
|
|
data.add(new Person("Manolo", 32)); |
|
|
|
data.add(new Person("Jorge", 2)); |
|
|
|
data.add(new Person("Pepe", 89)); |
|
|
|
|
|
|
|
//machaca el ultimo que ha sido escrito con nueva entrada |
|
|
|
//opt 1 : crear un array y serializarlo para despues leerlo |
|
|
|
//opt 2 : crear tantos archivos como obj alla xd |
|
|
|
boolean isWrited = ObjWriter.write(data,file); |
|
|
|
|
|
|
|
Person p = (Person) ObjReader.read(file); |
|
|
|
Person p2 = (Person) ObjReader.read(file); |
|
|
|
People dat = null; |
|
|
|
if (isWrited) { |
|
|
|
dat = (People) ObjReader.read(file); |
|
|
|
} |
|
|
|
if (dat != null){ |
|
|
|
System.out.println(dat.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
System.out.println(p); |
|
|
|
System.out.println(p2); |
|
|
|
} |
|
|
|
} |