Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. package utils;
  2. import java.io.*;
  3.  
  4. class compare {
  5. public static void main(String args[]) throws IOException {
  6.  
  7.  
  8.  
  9.  
  10. FileInputStream file1 = new InputStream(args[0]);
  11. FileInputStream file2 = new InputStream(args[1]);
  12.  
  13. try {
  14. if(args.length != 2)
  15. throw (new RuntimeException("Usage : java compare <filetoread> <filetoread>"));
  16.  
  17.  
  18. while (true) {
  19. int a = file1.read();
  20. int b = file2.read();
  21. if (a==-1) {
  22. System.out.println("Both the files have same content");
  23. }
  24. else{
  25. System.out.println("Contents are different");
  26. }
  27. }
  28.  
  29. }
  30. catch (IOException ioe) {
  31. System.out.println("Error: " + ioe);
  32. }
  33. catch (Exception e) {
  34. System.out.println("Error: " + e);
  35. }
  36.  
  37. }
  38. }
  39.  
  40. FileInputStream fin = new FileInputStream(args[i]);
  41. BufferedReader myInput = new BufferedReader
  42. (new InputStreamReader(fin));
  43. StringBuilder sb = new StringBuilder();
  44. while ((thisLine = myInput.readLine()) != null) {
  45. sb.append(thisLine);
  46. }
  47.  
  48. import java.io.*;
  49.  
  50. public class Testing {
  51. public static void main(String[] args) throws java.io.IOException {
  52.  
  53. BufferedReader bfr2 = new BufferedReader(new InputStreamReader(
  54. System.in));
  55. String s1 = "";
  56. String s2 = "", s3 = "", s4 = "";
  57. String y = "", z = "";
  58.  
  59. File file1 = new File("args[0]");
  60. File file2 = new File("args[1]");
  61.  
  62. BufferedReader bfr = new BufferedReader(new FileReader(file1));
  63. BufferedReader bfr1 = new BufferedReader(new FileReader(file2));
  64.  
  65. while ((z = bfr1.readLine()) != null)
  66. s3 += z;
  67.  
  68. while ((y = bfr.readLine()) != null)
  69. s1 += y;
  70.  
  71. System.out.println();
  72.  
  73. System.out.println(s3);
  74.  
  75. if (s3.equals(s1)) {
  76. System.out.println("Content of both files are same");
  77. } else {
  78.  
  79. System.out.println("Content of both files are not same");
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement