Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package igfollowers;
- import java.util.Scanner;
- import java.io.FileReader;
- import java.io.BufferedReader;
- import java.io.IOException;
- //import java.net.NetworkInterface;
- import java.io.*;
- //import java.io.FileNotFoundException;
- /*
- import java.io.File;
- import java.util.ArrayList;
- import java.util.List;
- */
- /*
- import difflib.Chunk;
- import difflib.Delta;
- import difflib.DiffUtils;
- import difflib.Patch;
- */
- public class IGFollowers {
- public static void main(String[]args) {
- Scanner e = new Scanner(System.in);
- int opcion = 0;
- do {
- opcion=escribirMenu(e);
- switch(opcion){
- case 1:
- duplicarLista();
- break;
- case 2:
- compararLista(e);
- break;
- case 3:
- System.out.println("\n\n\n\nSALIENDO DEL PROGRAMA");
- }
- }while (opcion!=3);
- e.close();
- }
- static int escribirMenu(Scanner e) {
- int op=0;
- System.out.println("1. Actualizar lista.");
- System.out.println("2. Comparar nombres.");
- System.out.println("3. Exit");
- System.out.print("\n\nOpción: ");
- op=e.nextInt();
- return op;
- }
- static void duplicarLista() {
- try {
- //DEFINIR CUAL ES EL ARCHIVO EN EL CUAL DEBEMOS INTRODUCIR LA LISTA DE USUARIOS
- File reciente = new File("E:\\Basura\\IGFollowers\\VersionReciente.txt"); //LISTA A INTRODICIR
- File antiguo = new File("E:\\Basura\\IGFollowers\\VersionAntigua.txt"); //EN LAPRIMERA VEZ QUE USAMOS EL PROGRAMA ESTA LISTA SERÁ IGUAL A LA ANTERIOR, PERO EN FUTUROS USOS NO SE DEBERIA DE TOCAR
- InputStream in = new FileInputStream(reciente);
- OutputStream out = new FileOutputStream(antiguo);
- //PROCEDIMIENTO PARA DUPLICAR EL ARCHIVO
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- in.close();
- out.close();
- }catch(IOException ioe) {}
- }
- static void compararLista(Scanner e) {
- try {
- String reciente="";
- String antiguo="";
- boolean iguales=true;
- FileReader leerReciente = new FileReader("E:\\Basura\\IGFollowers\\VersionReciente.txt");
- BufferedReader bufferLeerReciente = new BufferedReader(leerReciente);
- FileReader leerAntiguo = new FileReader("E:\\Basura\\IGFollowers\\VersionAntigua.txt");
- BufferedReader bufferLeerAntiguo = new BufferedReader(leerAntiguo);
- reciente = bufferLeerReciente.readLine();
- antiguo = bufferLeerAntiguo.readLine();
- while ((reciente!=null) && (antiguo!=null) && iguales) {
- if (!reciente.equals(antiguo))
- iguales = false;
- reciente = bufferLeerReciente.readLine();
- antiguo = bufferLeerAntiguo.readLine();
- }
- if ((iguales) && (reciente==null) && (antiguo==null))
- System.out.println("Los ficheros son iguales");
- else
- System.out.println("Los ficheros son diferentes");
- bufferLeerReciente.close();
- bufferLeerAntiguo.close();
- }catch(IOException ioe) {}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement