Java - ejercicio en java ayuda fichero

 
Vista:

ejercicio en java ayuda fichero

Publicado por java empresa (2 intervenciones) el 07/02/2018 13:10:00
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
132
package ejercicio01;
 
import java.util.Scanner;
import java.io.*;
 
public class Ejercicio01 {
 
    public static void mostrarMenu() {
        Scanner teclado = new Scanner(System.in);
        int opcion;
 
        do {
 
            System.out.println("1-.Agregar Empresa");
            System.out.println("2-.Mostrar Empresa");
            System.out.println("3-.Modificar Empresa");
            System.out.println("4-.Eliminar Empresa");
            System.out.println("5-.Salir");
 
            opcion = teclado.nextInt();
            switch (opcion) {
                case 1: {
                    crearFichero();
                    break;
                }
                case 2: {
                    mostrarFichero();
                    break;
                }
                 case 3: {
 
                    break;
                }
                  case 4: {
 
                    break;
                }
                case 5: {
 
						System.out.println("usted desea salir");
						System.out.println("1) para si   2) para no ");
						if(opcion !=1  ){
						opcion = teclado.nextInt();
						opcion=4+opcion;
						}
						opcion=opcion;
				}
				break;
 
                default: {
                    System.out.println("Opcion incorrecta");
                }
 
            }
        } while (opcion != 5);
    }
 
    public static void crearFichero() {
        FileWriter fw = null;
        try {
            fw = new FileWriter("empresa.txt");
            PrintWriter pw = new PrintWriter(fw);
            escribirFichero(pw);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            try {
                if (fw != null) {
                    fw.close();
                }
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }
 
    }
 
 
 
 
    public static void escribirFichero(PrintWriter pw) throws Exception {
        Scanner teclado = new Scanner(System.in);
        String opcion;
        System.out.print("Nombre de Empresa:  ");
        opcion = teclado.nextLine();
        pw.println(opcion);
        System.out.print("RIF de Empresa:   ");
        opcion = teclado.nextLine();
        pw.println(opcion);
        System.out.print("Telefono de Empresa:   ");
        opcion = teclado.nextLine();
        pw.println(opcion);
        System.out.print("--------------------------");
        System.out.println("--------------------------");
    }
    public static void leerFichero(BufferedReader br) throws Exception {
        String linea;
        linea = br.readLine();
        while (linea != null) {
 
            System.out.println(linea);
            linea = br.readLine();
 
        }
    }
 
    public static void mostrarFichero() {
        FileReader fr = null;
        try {
            File fichero = new File("empresa.txt");
            fr = new FileReader(fichero);
            BufferedReader br = new BufferedReader(fr);
            leerFichero(br);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            try {
                if (fr != null) {
                    fr.close();
                }
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }
 
    }
 
    public static void main(String[] args) {
        mostrarMenu();
    }
 
}


Buenos dias tengo un problema necesito hacer que el programa me almacene mas de una empresa y no puedo que me elimine una empresa pero buscando por un rif y que me deje modificar una empresa pero buscandola tambien por el rif si alguien me puede ayudar la necesito para culminar el semestre soy estudiante de 3 semestre de informatica
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder