Java 比较两个任意文件是否相同

springboot 文件差异化对比以及可视化展示 springboot 文件差异化对比以及可视化展示。 阅读详情

一、比较规则

  1. 先比较两个文件的长度,如果不一样则文件肯定不一样。
  2. 否则将文件读取出来,一个字节一个字节的比较二者内容是否相同。
public class FileCompare {
    public static void main(String[] args) {
        System.out.println("请依次输入两个文件的全路径和文件名:");
        System.out.println("firstFile:");
        String firstFile = inputFileName();
        System.out.println("secondFile:");
        String secondFile = inputFileName();
        System.out.println("Start to compare ...");
        FileCompare fileCompare = new FileCompare();
        fileCompare.compareFile(firstFile, secondFile);
    }

    private static String inputFileName() {
        BufferedReader buffRead = new BufferedReader(new InputStreamReader(System.in));
        String fileName = null;
        try {
            fileName = buffRead.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return fileName;
    }

    private void compareFile(String firFile, String secFile) {
        try {
            BufferedInputStream fir = new BufferedInputStream(new FileInputStream(firFile));
            BufferedInputStream sec = new BufferedInputStream(new FileInputStream(secFile));
            //比较文件的长度是否一样
            if (fir.available() == sec.available()) {
                while (true) {
                    int firRead = fir.read();
                    int secRead = sec.read();
                    if (firRead == -1 || secRead == -1) {
                        System.out.println("two files are same!");
                        break;
                    } else if (firRead != secRead) {
                        System.out.println("Files not same!");
                        break;
                    }
                }
            } else {
                System.out.println("two files are different!");
            }
            fir.close();
            sec.close();
            return;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

二、File 中的 length() 与IO中 InputStream 类中的 available()

1️⃣File 中的 length() 返回 long,表示文件的大小。
2️⃣IO 中 InputStream 类中的 available() 返回 int。表示该 inputstream 在不被阻塞的情况下一次可以读取到的数据长度。

Java课程设计 比较两个文件内容是否相同 运行前提:保存三个文本文件“text1.txt”、“text2.txt”、“text3.txt”到存放“IOOperation.java”的同一个文件夹中。其中两个文本文件内容相同,一个不同于其他两个。 运行方法:在命令行提示符模式下cd到“IOOperation.java”所 阅读详情

相关推荐

Java比较两个文件是否完全相同 JavaIO ApacheCommonIO Files.mismatch RandomAccessFile BufferedReader

原文链接:Compare the Content of Two Files in Java 1. Overview In this tutorial, we'll review different approaches to determine if the contents of two files are equal. We'll be using core Java Stream I/O libraries to read the contents of the files and imple

u011225581的专栏 1927

【Java SE】判断两个文件内容是否相同的多种方法

计算文件的哈希值(如 MD5、SHA-256 等),然后比较两个文件的哈希值。如果哈希值相同,则可以认为文件内容相同。这种方法适用于大文件,因为只需要比较哈希值而不是整个文件内容。Files;Path;

Hi there 6707

记录一下 Java 代码实现文件夹、文件的对比,主要包含 word、pdf、文本、图片等相关文件的对比计算,以及计算文本的相似率

记录一下 Java 代码实现文件夹、文件的对比,主要包含 word、pdf、文本、图片等相关文件的对比计算,以及计算文本的相似率(重复率)、筛选出差异的文件、方便文件和文档的去重,并封装为jar包

java文件比较_Java 比较两个任意文件是否相同

一、比较规则先比较两个文件的长度,如果不一样则文件肯定不一样。否则将文件读取出来,一个字节一个字节的比较二者内容是否相同。import java.io.*;public class FileCompare {public static void main(String[] args) {System.out.println("请依次输入两个文件的全路径和文件名:");System.out.prin...

weixin_28766581的博客 1119

SRAM Bank数量配置:性能、面积与功耗的权衡指南

SRAM(静态随机存取存储器)是芯片设计中的关键存储单元,其Bank数量配置直接影响访问延迟、吞吐率、功耗和面积。Bank切分通过将存储阵列分区,缩短位线和字线延迟,从而提升性能,但会增加外围电路开销。合理配置Bank数量可优化PPA(性能、功耗、面积),在28nm和16nm工艺下,2个Bank通常是性价比最高的选择。本文基于实测数据,探讨不同场景下的Bank配置策略,帮助工程师避免常见误区,提升设计效率。

weixin_27230891的博客 179

java判断两个文件是否相同

文章目录方式一:方式二: 方式一: 将文件一次性读入内存,然后通过MessageDigest进行MD5加密,最后再手动将其转换为16进制的MD5值。 /** * 计算文件的MD5值 * * @param file * @return */ public static String getFileMD5(File file) { if (!file.isFile()) { return null;

zhou_zhao_xu的博客 5899

音频DSP开发中的‘隐藏关卡’:那些SigmaStudio未公开的模块计算秘籍

本文深入探讨音频DSP开发中SigmaStudio未公开的模块计算秘籍,重点解析动态范围控制、均衡器参数映射和混响算法优化等核心模块计算公式。通过实际案例揭示如何利用这些非官方技巧提升音频质量与系统性能,为ADI DSP开发者提供宝贵的实战经验。

water的专栏 911

java比较两个list是否相同_Java判断两个List是否相同

1.利用Java中为List提供的方法retainAll()/*** 判断两个List内的元素是否相同* * 此方法有bug 见Food.class** @param list1* @param list2* @return*/private static boolean getDiffrent2(List list1, List list2) {long st = System.nanoTim...

weixin_39717318的博客 8963

[ensp报错:USG6000V错误代码45解决方案]

[ensp报错:USG6000V:错误代码45解决] [ensp报错:USG6000V:错误代码45解决] 第一种处理方式: ensp的45错误帮助文档里的解决方法:(这里就不说了,上华为爸爸的图) ensp的45错误:如果你的45错误不是描述的那个,可能是ensp与virtualbox不兼容了。 错误描述:具体表现为在virtualbox里没有vfw_usg的条目,虚拟介质管理器里也没有相应的条目: 就是vfw_usg_vdi这个 这种情况下你把ensp卸载重装多少次都没用,原因在两个软件的兼容

weixin_45456536的博客 3万+

微波射频学习笔记18-------偶极子天线和微波天线设计介绍

几种天线设计方法的介绍 一、偶极子天线 1.天线模型 两根紧挨着的金属导体,长度均为四分之一波长,直径均远小于波长,两导体间距也远小于波长。 2.天线性能的设计因素 ① 单个导体长度L:(光速/频率)/4=四分之一波长(在空气中传播的波长),但在导体中传播,波长会变短; ② 导体半径R:远小于波长即可,使用导电率高些的材料,市面上常见直径零点几毫米就挺好,或者用波长/200,得出一个小200的值,也算远小于波长; ③ 两导体间距S:远小于波长即可,可以比半径更小点。 以上三个变量L、R、S,均可在仿真软件

Sil_sprout 1万+

比较两个list集合是否相同

比较两个list集合是否相同 1.主要比较两个list中的元素,以及list的长度 2. list集合是有序的,并且list集合里的元素可以重复,因为该集合体系有索引 3.所以,list集合里元素可能有相同的,并且顺序可能不一样 第一种比较方法 下面展示一些 内联代码片。 package com.lrc.list; import java.util.ArrayList; import java...

chen的博客 2万+

AttifyOS 3.0实战:从固件提取到物联网设备安全评估全流程解析

本文详细解析了使用AttifyOS 3.0进行物联网设备安全评估的全流程。从获取D-Link路由器固件开始,到利用其预置的Binwalk等工具完成固件提取、解包Squashfs文件系统,并深入分析Web源码进行初步安全审计。这套集成系统极大简化了环境配置,让研究人员能专注于漏洞挖掘本身,是物联网安全评估的高效工具箱。

ice55的博客 214

比较两个对象中所有属性值是否相同

比较两个对象中所有属性值是否相同 /** * 比较两个实体属性值,返回一个boolean,true则表时两个对象中的属性值无差异 * @param obj1 进行属性比较的对象1 * @param obj2 进行属性比较的对象2 * @return 属性差异比较结果boolean */ public static boolean co...

爱谁谁博客 8031

深入解析poi-tl自定义表格渲染插件中的多级子循环实现

本文深入解析了poi-tl自定义表格渲染插件中的多级子循环实现,详细介绍了其在处理复杂业务数据时的核心价值、实现原理及实战技巧。通过多级子循环机制,开发者可以高效地将层级数据结构渲染到Word表格中,显著提升代码简洁性和维护效率。文章还分享了性能优化和异常处理经验,帮助开发者更好地应用该插件。

weixin_33734785的博客 483

想使用dify实现docx文档的自动生成?试了一圈,感觉还是根据python-docx更靠谱

在软件开发过程中,需求文档、设计文档等材料的编写是每个开发者都绕不开的工作。最近笔者接到一个需要批量生成标准化需求文档的任务,尝试了目前热门的低代码工具Dify后,发现对于稍微复杂格式的文档生成需求(例如文本居中这么简单的需求),最终还是回归到基于python-docx库的解决方案。本文将分享两种技术路线的对比实践。

xiezhipu的博客 2547

Java中比较两个SET是否相同

java api中,好像没有发现比较两个set 的内容是否一样的方法,只能自己写一个来实现了,其实也比较简单,比较记录数是否一样,然后看内容是否一致, 测试的方法如下: public static boolean equals(Set<?> set1, Set<?> set2){ if(set1 == null || set2 ==null){//...

HD243608836的博客 1万+

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

java 怎么比较两个map 是否相同

给大家整理了一些有关【Java,AP】的项目学习资料(附讲解~~):https://edu.51cto.com/course/35714.htmlhttps://edu.51cto.com/course/19064.htmlJava中比较两个Map是否相同的方案 在Java中,Map是一种常用的数据结构,用于存储键值对...

weixin_41838656的博客 558

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

比较两个文件内容是否相同

/* 判断两个文件的内容是否相同,文件名要用绝对路径 * @param fileName1 :文件1的绝对路径 * @param fileName2 :文件2的绝对路径 * @return 相同返回true,不相同返回false */ public boolean isSameFile(String...

datai3890的博客 2187

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

JAVA比较两个数组中的元素是否相同

import java.util.Arrays;         public class Test {                 /**                  * Java比较两个数组中的元素是否相同                  */                 public static void main(String[] args) { St

xiaoqiang21007的专栏 2934

java 比较两个文件是否相同

采用的策略:1)先比较两个文件的长度,如果不一样则文件肯定不一样                          2)如果文件一样长则将文件读取出来一个字节一个字节的比较他们的内容是否相同 代码: package file; import java.io.BufferedInputStream; import java.io.BufferedReader; import ja

oliveevilo的专栏 5702

JAVA -比较两个实体中相同属性名的值是否相同,有返回值

/** * 获取两个对象同名属性内容不相同的列表 * @param class1 对象1 * @param class2 对象2 * @return * @throws ClassNotFoundException * @throws IllegalAccessException */ public static List<Map<String, Object>> compareTwoClass(Obje.

qq_44257753的博客 2196

两个字符串比较是否有相同内容

如何查找两个字符串中是否有相同的部分,比如说存在两个字符串? 例:

weixin_43163515的博客 4248

java 定义一个方法,用于比较两个int数组的数字是否相同

定义一个方法,用于比较两个int数组的数字是否相同 分析: 1、定义方法: 方法的返回值为boolean类型 参数为两个数组(int[] arr1,int[] arr2) 2、比较数组长度是否一样; 3、使用for循环比较数组内容 3.1、声明boolean类型变量flag,初始值设为true 3.2、如果不同把flag赋值false,break跳出循环 public class Test03 { public static void main(String[] a

雁迟的博客 4103

JAVA比较两个数组中是否存在相同元素,并且取出相同元素(以两个String[]数组为例)

/** * 比较两个字符串数组的是否存在相同内容,并对相同内容以数组形式返回 * @param orgnElecAreaIdArr * @param chekElecAreaIdArr * @return */ private String[] compareTwoArraySame(String[] arr1, String[] arr...

qq_42755868的博客 3470

java list 比较_java 怎么比较两个list是否相同

判断两个list集合的元素个数是否相等。如果不相等则两个list集合也不相等,判断结束,32313133353236313431303231363533e58685e5aeb931333365643661如果相等则进入第二步判断判断list1的元素是否全部在list2中。遍历list1,取出list1中的元素,依次去list2中比较是否list2也存在这个元素。如果有任何一个list1中的元素在l...

weixin_39830313的博客 3985
上一篇: Java 发送邮件
下一篇: aeasyexcel 操作 Excel
JFS_Study
博客等级 码龄6年 363粉丝 359原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JFS_Study

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值