joseleonweb

Untitled

Feb 28th, 2021
594
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Compare two files.
  3.  *
  4.  * To use this program, specify the names
  5.  * of the files to be compared on the command line.
  6.  *
  7.  * java CompFile FIRST.TXT SECOND.TXT
  8.  */
  9.  
  10. package m3uf3bytestreams;
  11.  
  12. import java.io.*;
  13.  
  14. public class CompFiles {
  15.  
  16.     public static void main(String[] args) {
  17.         int i=0, j=0;
  18.        
  19.         // First make sure that both files have been specified.
  20.         if(args.length !=2) {
  21.             System.out.println("Usage: CompFiles f1 f2");
  22.             return;
  23.         }
  24.        
  25.         // Compare the files.
  26.         try (FileInputStream f1 = new FileInputStream(args[0]);
  27.              FileInputStream f2 = new FileInputStream(args[1]))
  28.         {
  29.             // Check the contents of each file.
  30.             do {
  31.                 i = f1.read();
  32.                 j = f2.read();
  33.                 if(i != j) break;
  34.             } while(i != -1 && j != -1);
  35.            
  36.             if(i != j)
  37.                 System.out.println("Files differ.");
  38.             else
  39.                 System.out.println("Files are the same.");
  40.         } catch(IOException exc) {
  41.             System.out.println("I/O Error: " + exc);
  42.         }
  43.     }
  44. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×