B dias! he creado un programa que crea un txt, seleccionando el nombre y el contenido, y me funciona perfectamente. He añadido saltos de línea y todo, pero debería terminar el bucle al escribir "q" y NO lo hace, alguien sabe por qué? Os paso código de lo que tengo hecho.
public class practicas04 {
static InputStreamReader isr = new InputStreamReader (System.in);
static BufferedReader br = new BufferedReader (isr);
public static void main(String[] args) throws IOException {
//crear archivo
String ruta = System.getProperty("user.dir")+File.separator;
String salt = System.getProperty("line.separator");
System.out.print("Introduzca el Nombre del Archivo: ");
String file = br.readLine();
System.out.print("Introduzca el Contenido del Archivo: ");
String text = br.readLine();
FileWriter fw = new FileWriter (ruta+file+".txt");
BufferedWriter bw = new BufferedWriter (fw);
bw.write(text+salt);
bw.flush(); //obliga al buffer a escribir en el archivo.
while (text != "q") {
text = br.readLine();
bw.write(text+salt);
bw.flush();
}//end while
bw.close();
System.out.print("El Archivo "+file+".txt se ha Creado con Éxito! en\n "+ruta);
}//end main
}//end class
readLine()
que como su nombre indica, lee una línea que termina cuando llega el salto de línea, tecla Enter. Si quieres que pueda seguir escribiendo, tendrás que volver a llamar areadLine()
, hasta que se cumpla la condición de salida, que la verdad, no me imagino cómo podrías hacerla... – SuperG280 el 21 abr. 20 a las 8:21