Advertisement
Guest User

Untitled

a guest
May 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package Ficheiro;
  2.  
  3. import java.io.*;
  4. import Registos.*;
  5. public class FicheiroEvento_Joel {
  6.    
  7.     public static final String NOME_FICHEIRO = "RegistoEvento.bin";
  8.  
  9.     public RegistoEvento ler() {
  10.         RegistoEvento re;
  11.         try {
  12.             ObjectInputStream in = new ObjectInputStream(
  13.                     new FileInputStream(NOME_FICHEIRO));
  14.             try {
  15.                 re = (RegistoEvento) in.readObject();
  16.             } finally {
  17.                 in.close();
  18.             }
  19.             return re;
  20.         } catch (IOException | ClassNotFoundException ex) {
  21.             return null;
  22.         }
  23.     }
  24.  
  25.     public boolean guardar(RegistoEvento re) {
  26.         try {
  27.             ObjectOutputStream out = new ObjectOutputStream(
  28.                     new FileOutputStream(NOME_FICHEIRO));
  29.             try {
  30.                 out.writeObject(re);
  31.             } finally {
  32.                 out.close();
  33.             }
  34.             return true;
  35.         } catch (IOException ex) {
  36.             return false;
  37.         }
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement