Server IP : 172.16.15.8 / Your IP : 3.135.206.25 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/zan/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
/** File Name: CompareAssn.java Author: Regina Barner Date: 25 February 2013 Instructor: Dr. Wang Goal: Create a program to simulate compare/'cmp' UNIX system command. Compare two files together and output whether the files are identical or not. */ import java.util.Scanner; import java.util.Arrays; import java.io.File; public class CompareAssn { public static final int MAX = 100; public static void main(String[] args) throws java.io.FileNotFoundException { for(int i=0; i<args.length; i++) System.out.println(args[i]); if(args.length<2) System.out.println("Need two files to compare, please try again. \n"); else { Scanner input1 = new Scanner(new File(args[0])); Scanner input2 = new Scanner(new File(args[1])); String[] compare1 = new String[MAX]; String[] compare2 = new String[MAX]; int size1 = 0; int size2 = 0; int ncount = 0; boolean bool = true; while(input1.hasNext() && input2.hasNext()) { compare1[size1] = input1.next(); size1 ++; compare2[size2] = input2.next(); size2 ++; } if(Arrays.equals(compare1, compare2) == true) System.out.println("The files are identical. \n"); else System.out.println("The files are NOT identical. \n"); input1.close(); input2.close(); } } }