集册 Java实例教程 文件内容等于

文件内容等于

欢马劈雪     最近更新时间:2020-01-02 10:19:05

562
文件内容等于
/** from nowjava.com - 时  代  Java**/


//package com.nowjava;

import java.io.File;

import java.io.FileInputStream;


public class Main {

    public static void main(String[] argv) throws Exception {

        File file1 = new File("Main.java");

        File file2 = new File("Main.java");

        System.out.println(fileEquals(file1, file2));

    }


    public static boolean fileEquals(File file1, File file2) {

        try {

            FileInputStream f1 = new FileInputStream(file1);

            FileInputStream f2 = new FileInputStream(file2);/*from 时代Java - nowjava.com*/

            byte[] b1 = new byte[(int) file1.length()];

            byte[] b2 = new byte[(int) file2.length()];

            f1.read(b1);

            f2.read(b2);

            for (int j = 0; j < b1.length; j++) {

                if (b1[j] != 
展开阅读全文