package Hola;
import java.io.*;
import javax.swing.JOptionPane;
public class Jade {
public static void main(String args[]) throws IOException {
// new RandomAccessFile("archivo.txt", "rw"); // No se usa?
String telefono;
String opc;
int respuesta;
String nombre;
String direccion;
// String resul; // No se usa??
BufferedWriter bw = new BufferedWriter(new FileWriter("archivo.txt"));
PrintWriter salida = new PrintWriter(bw);
try {
opc = JOptionPane.showInputDialog(null, "Desea ingresar un nuevo contacto SI=1 NO=2");
respuesta = Integer.parseInt(opc);
while (respuesta == 1) {
nombre = JOptionPane.showInputDialog(null, "ingrese el nombre");
direccion = JOptionPane.showInputDialog(null, "ingrese la direccion");
telefono = JOptionPane.showInputDialog(null, "ingrese el numero de telefono");
salida.println(" " + nombre + telefono + direccion);
opc = JOptionPane.showInputDialog(null, "Desea ingresar un nuevo contacto SI=1 NO=2");
respuesta = Integer.parseInt(opc);
}
JOptionPane.showMessageDialog(null, "Hasta luego");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Ha habido un error. El programa se cerrara.");
System.err.println(e);
} finally {
salida.close();
bw.close();
}
}
}