-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeerArchSecuencialSerializable.java
More file actions
66 lines (53 loc) · 1.68 KB
/
LeerArchSecuencialSerializable.java
File metadata and controls
66 lines (53 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package farmaciaapp;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
public class LeerArchSecuencialSerializable {
private ObjectInputStream archEntrada;
private String nomArch;
public LeerArchSecuencialSerializable(String nomArch) {
this.nomArch = nomArch;
}
public void abrirArchivo() {
try {
archEntrada = new ObjectInputStream(
new FileInputStream(nomArch));
} catch (IOException e) {
System.err.println("Error al abrir el archivo.");
}
}
public ArrayList leerArrayList() {
ArrayList al = null;
try {
al = (ArrayList) archEntrada.readObject();
return al;
} catch (EOFException e) {
System.err.println("Error EOF");
}
catch (ClassNotFoundException e) {
System.err.println("No se pudo crear el objeto.");
}
catch (IOException e) {
System.err.println("Error al leer del archivo.");
}
return null;
}
public void cerrarArchivo() {
try {
if (archEntrada != null) {
archEntrada.close();
}
//System.exit(0); Sale de la aplicacion
} catch (IOException e) {
System.err.println("Error al cerrar el archivo.");
//System.exit(1);
}
}
}