mBull

Reader

Jun 13th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package DataBase;
  6.  
  7. import Contact.Family;
  8. import Contact.Person;
  9. import com.thoughtworks.xstream.XStream;
  10. import java.io.BufferedReader;
  11. import java.io.EOFException;
  12. import java.io.FileNotFoundException;
  13. import java.io.FileReader;
  14. import java.io.IOException;
  15. import java.io.ObjectInputStream;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20.  
  21. /**
  22.  *
  23.  * @author Jeroen
  24.  */
  25. public class LoadXML {
  26.  
  27.     private XStream xstream;
  28.     private PersonDB personeneDatabank;
  29.     private ArrayList<Object> objecten = new ArrayList<Object>();
  30.  
  31.     public LoadXML(PersonDB persondb) {
  32.         FileReader fileRead = null;
  33.         xstream = new XStream();
  34.         try {
  35.             this.personeneDatabank = persondb;
  36.             fileRead = new FileReader("C:\\javaVGO.xml");
  37.             BufferedReader bufferRead = new BufferedReader(fileRead);
  38.             try {
  39.                 ObjectInputStream in = xstream.createObjectInputStream(bufferRead);
  40.  
  41.                 try {
  42.                     //it works this way, but I don't know how many objects are in the stream
  43.                     // so and I don't know the object type.
  44.                     // i Need a loop and a check here
  45.                             Person persoon = (Person) in.readObject();
  46.                             System.out.println(persoon.getFirstName());
  47.                             Person persoonb = (Person) in.readObject();
  48.                             System.out.println(persoonb.getFirstName());
  49.  
  50.                 } catch (ClassNotFoundException ex) {
  51.                     Logger.getLogger(LoadXML.class.getName()).log(Level.SEVERE, null, ex);
  52.                 }
  53.             } catch (IOException ex) {
  54.                 Logger.getLogger(LoadXML.class.getName()).log(Level.SEVERE, null, ex);
  55.             }
  56.  
  57.         } catch (FileNotFoundException ex) {
  58.             Logger.getLogger(LoadXML.class.getName()).log(Level.SEVERE, null, ex);
  59.         } finally {
  60.             try {
  61.                 fileRead.close();
  62.             } catch (IOException ex) {
  63.                 Logger.getLogger(LoadXML.class.getName()).log(Level.SEVERE, null, ex);
  64.             }
  65.         }
  66.  
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment