home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-02-11 | 1.7 KB | 55 lines |
- /*
- * @version @(#)Compare.java 1.2 98/05/15
- *
- * Copyright (c) 1997-1998 Sun Microsystems, Inc. All Rights Reserved.
- *
- * This software is the confidential and proprietary information of Sun
- * Microsystems, Inc. ("Confidential Information"). You shall not
- * disclose such Confidential Information and shall use it only in
- * accordance with the terms of the license agreement you entered into
- * with Sun.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
- * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
- * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
- * THIS SOFTWARE OR ITS DERIVATIVES.
- */
-
- import java.io.*;
-
- public class Compare {
-
- /*
- * compare file name1 and name2 one bye at a time
- */
- public static boolean compare(String name1, String name2) throws IOException {
- FileInputStream file1 = new FileInputStream(new File(name1));
- FileInputStream file2 = new FileInputStream(new File(name2));
- return compare(file1, file2);
- }
-
- /*
- * compare file1 and file2 one bye at a time
- */
- public static boolean compare(FileInputStream file1,
- FileInputStream file2) throws IOException {
- int b1 = file1.read();
- int b2 = file2.read();
- while (b1 >= 0 && b2 >= 0) {
- if (b1 != b2)
- return false;
-
- b1 = file1.read();
- b2 = file2.read();
- }
-
- return (b1 < 0 && b2 < 0);
- }
-
- public static void main(String[] args) throws IOException {
- System.out.println("The files are " + (Compare.compare(args[0], args[1]) ? "equal" : "not equal"));
- }
- }
-