Advertisement
Guest User

ejerc19

a guest
Oct 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, ClassNotFoundException {
  2.        
  3.        File fichero = new File("C:\\Users\\usuario\\Desktop\\NuevaCarpeta\\cursos2.dat");
  4.         FileInputStream filein = new FileInputStream(fichero);
  5.         ObjectInputStream dataIS = new ObjectInputStream(filein);
  6.         System.out.println("Comienza el proceso de creacion del fichero a XML...");
  7.  
  8.         //Creamos un objeto Lista de Personas
  9.         ListaCursos lista = new ListaCursos();
  10.  
  11.         try {
  12.             while(true) { //lectura del fichero
  13.             Curso c = (Curso) dataIS.readObject();
  14.  //añadir persona a la lista
  15.             lista.add(c); //añadir persona a la lista
  16.             }
  17.         } catch (EOFException e) {}
  18.                 dataIS.close();
  19.  
  20.         try {
  21.             XStream xstream = new XStream();
  22.             //cambiar de nombre a las etiquetas XML
  23.  
  24.             xstream.toXML(lista, new FileOutputStream("C:\\Users\\usuario\\Desktop\\NuevaCarpeta\\cursos2.xml"));
  25.             System.out.println("Creando fichero XML...");
  26.         } catch(Exception e) {
  27.                 e.printStackTrace();
  28.         }
  29.     }
  30.        
  31.        
  32.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement