Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void guardarListado(ArrayList<Persona> listado, String ruta) {
- File fichero = new File(ruta);
- try {
- FileOutputStream ficEscritu = new FileOutputStream(fichero);
- ObjectOutputStream guardarObjetos = new ObjectOutputStream(ficEscritu);
- for (Persona per : listado) {
- guardarObjetos.writeObject(per);
- }
- guardarObjetos.close();
- } catch (IOException e) {
- }
- }
- public static ArrayList volcarFicheroEnUnArrayList(String ruta) {
- Persona persona;
- ArrayList listado = new ArrayList();
- FileInputStream fichLectura = null;
- File fichero = new File(ruta);
- if (fichero.isFile() && fichero.exists()) {
- try {
- fichLectura = new FileInputStream(fichero);
- ObjectInputStream leerObjetos = new ObjectInputStream(fichLectura);
- while (true) {
- persona = (Persona) leerObjetos.readObject();
- listado.add(persona);
- }
- } catch (EOFException e) {
- System.out.println("Hemos volcado la informacion de los empleados en el array");
- try {
- fichLectura.close();
- } catch (IOException ex) {
- Logger.getLogger(Utilidades.class.getName()).log(Level.SEVERE, null, ex);
- }
- } catch (FileNotFoundException ex) {
- System.out.println("No existe el fichero");
- } catch (IOException ex) {
- Logger.getLogger(Utilidades.class.getName()).log(Level.SEVERE, null, ex);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(Utilidades.class.getName()).log(Level.SEVERE, null, ex);
- }
- } else {
- System.out.println("No existe el fichero");
- }
- //
- return listado;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement