Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Entregable;
- import java.io.File;
- import java.io.FileWriter;
- import java.util.Scanner;
- import Entregable.exception.TooHighNumberException;
- /**
- *
- * @author javie
- */
- public class DescifradoCesar {
- public static void main(String[] args) {
- FileWriter fw = null;
- Scanner scFile = null;
- String nombreFichero = args[0];
- int des = Integer.parseInt(args[1]);
- char[] linea;
- String texto = "";
- File f = new File(nombreFichero);
- File fe = new File("./" + nombreFichero + ".uncfr");
- if (!f.exists()) {
- System.out.println("El fichero no existe");
- } else {
- try {
- scFile = new Scanner(f);
- fw = new FileWriter(fe);
- while (scFile.hasNextLine()) {
- linea = scFile.nextLine().toCharArray();
- for (char letra : linea) {
- texto = texto + cifrado.cifrar(letra, des, true);
- }
- fw.write(texto + "\n");
- texto = "";
- }
- System.out.println("Fichero descifrado");
- } catch (TooHighNumberException e) {
- System.out.println("Desplazamiento fuera del limite");
- } catch (Exception e) {
- System.out.println("Se ha producido un error");
- } finally {
- if (scFile != null) {
- scFile.close();
- }
- if (fw != null) {
- try {
- fw.close();
- } catch (Exception e) {
- System.out.println("Error al cerrar");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement