daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest May 16th, 2018 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.dei.it3_pprog.files;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5. import org.dei.it3_pprog.AreaRestrita;
  6. import org.dei.it3_pprog.registos.RegistoAreasRestritas;
  7.  
  8. /**
  9.  *
  10.  * @author gcabral
  11.  */
  12. public class FicheiroRegistoAreasRestritas {
  13.  
  14.     public static final String NOME_FILE = "RegistoAreasRestritas.ra";
  15.  
  16.     public FicheiroRegistoAreasRestritas() {
  17.     }
  18.  
  19.     public RegistoAreasRestritas read() throws IOException {
  20.         return read(new File(NOME_FILE));
  21.     }
  22.  
  23.     public RegistoAreasRestritas read(String nomeFile) throws IOException {
  24.         return read(new File(nomeFile));
  25.     }
  26.  
  27.     public RegistoAreasRestritas read(File file) throws IOException {
  28.         RegistoAreasRestritas regAR;
  29.         try {
  30.             ObjectInputStream in = new ObjectInputStream(
  31.                     new FileInputStream(file));
  32.             try {
  33.                 regAR = (RegistoAreasRestritas) in.readObject();
  34.             } finally {
  35.                 in.close();
  36.             }
  37.             return regAR;
  38.         } catch (IOException | ClassNotFoundException ex) {
  39.             return new RegistoAreasRestritas();
  40.         }
  41.     }
  42.  
  43.     public static boolean write(RegistoAreasRestritas regAR) {
  44.         return FicheiroRegistoAreasRestritas.write(new File(NOME_FILE), regAR);
  45.     }
  46.  
  47.     public static boolean write(File file, RegistoAreasRestritas regAR) {
  48.         try {
  49.             ObjectOutputStream out = new ObjectOutputStream(
  50.                     new FileOutputStream(file));
  51.             try {
  52.                 out.writeObject(regAR);
  53.             } finally {
  54.                 out.close();
  55.             }
  56.             return true;
  57.         } catch (IOException ex) {
  58.             return false;
  59.         }
  60.     }
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top