Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package entregable01;
- import com.entregable.exceptions.LongKeyException;
- import com.entregable.utils.Utils;
- import java.io.*;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author jairo
- */
- public class CifrarFichero {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- String nombre;
- String linea;
- String salida = "";
- int codigo;
- if (args.length == 0) {
- nombre = "./test/Ejemplo.txt";
- codigo = -26;
- } else {
- nombre = args[0];
- codigo = Integer.parseInt(args[1]);
- }
- // LongKey(codigo);
- File f = new File(nombre);
- if (!f.exists()) {
- System.out.println("El fichero no existe");
- } else {
- Scanner inFile = null;
- File fi = null;
- FileWriter fw = null;
- try {
- fi = new File(nombre + ".cfr");
- inFile = new Scanner(f);
- fw = new FileWriter(fi);
- while (inFile.hasNextLine()) {
- linea = inFile.nextLine();
- String cifrar = Utils.cifrar(linea, codigo);
- salida = salida + cifrar + "\n";
- }
- fw.write(salida);
- }catch (LongKeyException LO){
- System.out.println(LO.getMessage());
- } catch (Exception e) {
- System.out.println("Se ha producido un error");
- e.printStackTrace();
- } finally {
- if (inFile != null) {
- inFile.close();
- }
- if (!fw.equals(null)) {
- try {
- fw.close();
- } catch (IOException ex) {
- System.out.println("Error al cerrar");
- }
- }
- }
- }
- }
- // public static void LongKey(int codigo) {
- // if(codigo > 25 || codigo < -25){
- // try {
- // throw new LongKeyException();
- // } catch (LongKeyException ex) {
- // System.out.println(ex.getMessage());
- // }
- // }
- //
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement