Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    /**
     * Returns true if files are same and false value if the files are different.
     * This function is very slow, so it will probably need a rewrite.
     * @param fileIS1 Input stream associated with the first file
     * @param fileIS2 Input stream associated with the second file
     * @return True if the files are the same, false otherwise.
     * @throws IOException if an error is encountered.
     */
    public static boolean sameContents(InputStream fileIS1, InputStream fileIS2) throws IOException {
        int b1 = fileIS1.read();
        int b2 = fileIS2.read();
        while ((b1 != -1) && (b2 != -1)) {
            if (b1 != b2) {
                return false;
            }
            b1 = fileIS1.read();
            b2 = fileIS2.read();
        }
        return b1 == b2;
    }
}