
BufferedReader, me devulve null al pinchar la opción de VER DATOS PABELLON
Publicado por y2h (5 intervenciones) el 11/11/2014 20:39:23
package Proyectos;
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JOptionPane;
public class ProyB_FicherosSec_opt2 {
public static void main(String[] args) {
String[] menu = {"Introducir Pabellón","Ver datos de Pabellón","Ver Pabellón de mayor aforo","Ver Pabellones construidos según fecha","Salir"};
int count,count2;
int encontrado;
int x=0;
int y=0;
String codigo, descripcion, aforo, fecha;
String buscar = null;
String[] codP = new String[100];
String[] desc = new String[100];
String[] afo = new String[100];
String[] fech = new String[100];
boolean salir = false;
try {
while(salir == false){
int menu2 = JOptionPane.showOptionDialog (null, "Opciones", "MENÚ", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, menu, menu[0]);
File f = new File("C:/","Pabellones.dat");
FileWriter fiw = new FileWriter(f, true);
BufferedWriter bfw = new BufferedWriter(fiw);
FileReader fir = new FileReader(f);
BufferedReader bfr = new BufferedReader(fir);
count2=0;
encontrado=0;
while((x=bfr.read())!= -1){
if((char)x =='#'){
count2++;
}
}
count=0;
for(int a=0; a>count2;a++){
codP[count]="";
desc[count]="";
afo[count]="";
fech[count]="";
while((y=bfr.read())!='&'){
codP[count]=codP[count]+(char)y;
}
while((y=bfr.read())!='&'){
desc[count]=desc[count]+(char)y;
}
while((y=bfr.read())!='&'){
afo[count]=afo[count]+(char)y;
}
while((y=bfr.read())!='#'){
fech[count]=fech[count]+(char)y;
}
count++;
}
if(menu2 == 0){ //INTRODUCIR PABELLÓN
codigo = JOptionPane.showInputDialog("Código del Pabellón");
for(int i = 0;i<codigo.length();i++){
bfw.write(codigo.charAt(i));
}
bfw.write("&"); //separador
descripcion = JOptionPane.showInputDialog("Descripción del Pabellón");
for(int i = 0;i<descripcion.length();i++){
bfw.write(descripcion.charAt(i));
}
bfw.write("&"); //separador
aforo = JOptionPane.showInputDialog("Aforo del Pabellón");
for(int i = 0;i<aforo.length();i++){
bfw.write(aforo.charAt(i));
}
bfw.write("&"); //separador
fecha = JOptionPane.showInputDialog("Fecha de contrucción del pabellón");
for(int i=0; i<fecha.length(); i++){
bfw.write(fecha.charAt(i));
}
bfw.write("#"); //finalización de registro
bfw.close();
}
if (menu2 == 1){ //VER DATOS DE PABELLÓN
buscar = JOptionPane.showInputDialog("Introduzca el código del pabellón para visualizar los datos");
for(int j = 0;j<codP.length;j++){
if(buscar.equals(codP[j])){
encontrado = j;
}
}
JOptionPane.showMessageDialog(null,"DATOS DE PABELLÓN" +"\n" + "\n"
+ "Código: " + codP[encontrado] +"\n"+ "Descripción: " + desc[encontrado]+"\n"
+ "Aforo: " + afo[encontrado] +"\n"+ "Fecha de contrucción: "
+ fech[encontrado]);
}
bfr.close();
if(menu2 == 4){ //SALIR
System.exit(0);
}
}
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException IOE)
{
IOE.printStackTrace();
}
System.out.println("\nEjecución terminada.");
}
}
Valora esta pregunta


0