public class Cifrado_Cesar { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String nombreFichero = ""; int desplazamiento = 0; FileWriter fw = null; String textoCifrado; if (args.length >= 1) { nombreFichero = args[0]; desplazamiento = Integer.parseInt(args[1]); } else { nombreFichero = "./Prueba1.txt"; desplazamiento = 2; } if (desplazamiento > 26 || desplazamiento < -26) { System.out.println("Error ---> El desplazamiento no puede ser > 26 ni < -26"); } else { textoCifrado = cifrarFichero(nombreFichero, desplazamiento); //File f2 = new File("./cifrado_Cesar.cfr"); File f2 = new File(nombreFichero + ".cfr"); try { fw = new FileWriter(f2); fw.write(textoCifrado); } catch (IOException ex) { System.out.println("ERROR ---> " + ex.getMessage()); } finally { if (fw != null) { try { fw.close(); } catch (Exception e) { System.out.println("Error al cerrar"); } } } System.out.println("¡Cifrado completado!"); //System.out.println("Te hemos creado un archivo llamado cifrado_Cesar.cfr en el que tienes tu texto cifrado."); System.out.println("Te hemos creado un archivo llamado " + nombreFichero + ".cfr" + " en el que tienes tu texto cifrado."); System.out.println("Gracias por trabajar con nosotros. Que la fuerza te acompañe."); System.out.println(); // System.out.println("Desplazamiento: " + desplazamiento); } } }