Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.145.97.235
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 (0755) :  /home/thchang/cs440/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/thchang/cs440/Compare.java
//
//Assignment 5
//Name:	Compare.java
//
//Author:	Tyler Chang
//Instructor:	Dr. John Wang
//Course:	CS 440
//
//Due: Feb 23, 2015
//
//Goal:	Write a Java program to simulate the "cmp" command
//	receives two files as parameters and lists the line
//	number of the differences.
//	If there are no differences returns EOF. (End of File)
//

import java.util.Scanner;
import java.io.File;

public class Compare
{
	// main method
	public static void main(String[] args)
		throws java.io.IOException
	{
		// setup files and i/o streams
		File src1 = new File(args[0]);
		File src2 = new File(args[1]);
		Scanner input1 = new Scanner(src1);
		Scanner input2 = new Scanner(src2);

		// loop through and find differences
		for(int i = 1; input1.hasNextLine() && input2.hasNextLine(); i++)
		{
			if(input1.nextLine().compareTo(input2.nextLine()) != 0)
			{
				System.out.println(args[0] + " and " + args[1] + " differ: line " + i);
				return;
			}
		}

		// if we get to here then there were no differences
		if(! input1.hasNextLine())
			System.out.println("EOF on " + args[0]);
		else
			System.out.println("EOF on " + args[1]);
	}
}

Stv3n404 - 2023