Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. package igfollowers;
  2.  
  3. import java.util.Scanner;
  4. import java.io.FileReader;
  5. import java.io.BufferedReader;
  6. import java.io.IOException;
  7. //import java.net.NetworkInterface;
  8. import java.io.*;
  9. //import java.io.FileNotFoundException;
  10. /*
  11. import java.io.File;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. */
  15. /*
  16. import difflib.Chunk;
  17. import difflib.Delta;
  18. import difflib.DiffUtils;
  19. import difflib.Patch;
  20. */
  21. public class IGFollowers {
  22. public static void main(String[]args) {
  23. Scanner e = new Scanner(System.in);
  24.  
  25. int opcion = 0;
  26.  
  27. do {
  28. opcion=escribirMenu(e);
  29. switch(opcion){
  30. case 1:
  31. duplicarLista();
  32. break;
  33. case 2:
  34. compararLista(e);
  35. break;
  36. case 3:
  37. System.out.println("\n\n\n\nSALIENDO DEL PROGRAMA");
  38. }
  39. }while (opcion!=3);
  40.  
  41. e.close();
  42. }
  43.  
  44. static int escribirMenu(Scanner e) {
  45. int op=0;
  46. System.out.println("1. Actualizar lista.");
  47. System.out.println("2. Comparar nombres.");
  48. System.out.println("3. Exit");
  49.  
  50. System.out.print("\n\nOpción: ");
  51. op=e.nextInt();
  52. return op;
  53. }
  54.  
  55. static void duplicarLista() {
  56. try {
  57. //DEFINIR CUAL ES EL ARCHIVO EN EL CUAL DEBEMOS INTRODUCIR LA LISTA DE USUARIOS
  58. File reciente = new File("E:\\Basura\\IGFollowers\\VersionReciente.txt"); //LISTA A INTRODICIR
  59. 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
  60. InputStream in = new FileInputStream(reciente);
  61. OutputStream out = new FileOutputStream(antiguo);
  62. //PROCEDIMIENTO PARA DUPLICAR EL ARCHIVO
  63. byte[] buf = new byte[1024];
  64. int len;
  65.  
  66. while ((len = in.read(buf)) > 0) {
  67. out.write(buf, 0, len);
  68. }
  69. in.close();
  70. out.close();
  71. }catch(IOException ioe) {}
  72. }
  73.  
  74. static void compararLista(Scanner e) {
  75. try {
  76. String reciente="";
  77. String antiguo="";
  78. boolean iguales=true;
  79.  
  80. FileReader leerReciente = new FileReader("E:\\Basura\\IGFollowers\\VersionReciente.txt");
  81. BufferedReader bufferLeerReciente = new BufferedReader(leerReciente);
  82. FileReader leerAntiguo = new FileReader("E:\\Basura\\IGFollowers\\VersionAntigua.txt");
  83. BufferedReader bufferLeerAntiguo = new BufferedReader(leerAntiguo);
  84.  
  85. reciente = bufferLeerReciente.readLine();
  86. antiguo = bufferLeerAntiguo.readLine();
  87.  
  88. while ((reciente!=null) && (antiguo!=null) && iguales) {
  89.  
  90. if (!reciente.equals(antiguo))
  91. iguales = false;
  92.  
  93. reciente = bufferLeerReciente.readLine();
  94. antiguo = bufferLeerAntiguo.readLine();
  95. }
  96. if ((iguales) && (reciente==null) && (antiguo==null))
  97. System.out.println("Los ficheros son iguales");
  98. else
  99. System.out.println("Los ficheros son diferentes");
  100.  
  101. bufferLeerReciente.close();
  102. bufferLeerAntiguo.close();
  103. }catch(IOException ioe) {}
  104. }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement