Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.dei.it3_pprog.files;
- import java.io.*;
- import java.util.*;
- import org.dei.it3_pprog.AreaRestrita;
- import org.dei.it3_pprog.registos.RegistoAreasRestritas;
- /**
- *
- * @author gcabral
- */
- public class FicheiroRegistoAreasRestritas {
- public static final String NOME_FILE = "RegistoAreasRestritas.ra";
- public FicheiroRegistoAreasRestritas() {
- }
- public RegistoAreasRestritas read() throws IOException {
- return read(new File(NOME_FILE));
- }
- public RegistoAreasRestritas read(String nomeFile) throws IOException {
- return read(new File(nomeFile));
- }
- public RegistoAreasRestritas read(File file) throws IOException {
- RegistoAreasRestritas regAR;
- try {
- ObjectInputStream in = new ObjectInputStream(
- new FileInputStream(file));
- try {
- regAR = (RegistoAreasRestritas) in.readObject();
- } finally {
- in.close();
- }
- return regAR;
- } catch (IOException | ClassNotFoundException ex) {
- return new RegistoAreasRestritas();
- }
- }
- public static boolean write(RegistoAreasRestritas regAR) {
- return FicheiroRegistoAreasRestritas.write(new File(NOME_FILE), regAR);
- }
- public static boolean write(File file, RegistoAreasRestritas regAR) {
- try {
- ObjectOutputStream out = new ObjectOutputStream(
- new FileOutputStream(file));
- try {
- out.writeObject(regAR);
- } finally {
- out.close();
- }
- return true;
- } catch (IOException ex) {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement