Closed dongbinlu closed 2 months ago
@Test public void testhash()throws Exception{ String fileName = TestFileUtil.getPath() + "hash" + ".xlsx"; File file = new File(fileName); EasyExcel.write(file, DemoData.class) .sheet("模板") .doWrite(() -> { // 分页查询数据 return data(); }); file.setLastModified(0L); file.setExecutable(false); file.setReadable(true); file.setWritable(true); File file1 = new File(fileName); byte[] bytes = calculateFileHash(file1); String hexString = HexUtils.toHexString(bytes); System.out.println(hexString); } public static byte[] calculateFileHash(InputStream inputStream) throws Exception { MessageDigest digest = MessageDigest.getInstance("SHA-256"); try (DigestInputStream dis = new DigestInputStream(inputStream, digest)) { byte[] buffer = new byte[1024 * 1024 * 500]; // 500 MB buffer int bytesRead; while ((bytesRead = dis.read(buffer)) != -1) { // Read buffer data and update digest digest.update(buffer, 0, bytesRead); } // Get the final hash value return digest.digest(); } }
文件内容相同,为什么每次生成的文件hash不一致
excel 本质是一个压缩包,里面存放了一些xml文件。文件的创建时间、所在环境都会影响hash值。这符合hash的定义。
不知道您是否已经解决该问题?我们先暂时关闭这个问题,如果还存在问题请重新Reopen这个issue。
异常代码
异常提示
问题描述
文件内容相同,为什么每次生成的文件hash不一致