Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package DataBase;
- import Contact.Family;
- import Contact.Person;
- import com.thoughtworks.xstream.XStream;
- import java.io.BufferedReader;
- import java.io.EOFException;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author Jeroen
- */
- public class LoadXML {
- private XStream xstream;
- private PersonDB personeneDatabank;
- private ArrayList<Object> objecten = new ArrayList<Object>();
- public LoadXML(PersonDB persondb) {
- FileReader fileRead = null;
- xstream = new XStream();
- try {
- this.personeneDatabank = persondb;
- fileRead = new FileReader("C:\\javaVGO.xml");
- BufferedReader bufferRead = new BufferedReader(fileRead);
- try {
- ObjectInputStream in = xstream.createObjectInputStream(bufferRead);
- try {
- //it works this way, but I don't know how many objects are in the stream
- // so and I don't know the object type.
- // i Need a loop and a check here
- Person persoon = (Person) in.readObject();
- System.out.println(persoon.getFirstName());
- Person persoonb = (Person) in.readObject();
- System.out.println(persoonb.getFirstName());
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(LoadXML.class.getName()).log(Level.SEVERE, null, ex);
- }
- } catch (IOException ex) {
- Logger.getLogger(LoadXML.class.getName()).log(Level.SEVERE, null, ex);
- }
- } catch (FileNotFoundException ex) {
- Logger.getLogger(LoadXML.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- try {
- fileRead.close();
- } catch (IOException ex) {
- Logger.getLogger(LoadXML.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment