日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

JDK 12的Files.mismatch方法

發布時間:2023/12/3 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JDK 12的Files.mismatch方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

JDK 12向Files類引入了一種新方法。 方法Files.mismatch(Path,Path)已通過JDK-8202302引入JDK 12,并在JDK 12 Early Access Build 20 (支持新{@systemProperty} Javadoc標記的相同早期訪問版本)中可用 。

JDK-8202302 [“用于比較文件的(fs)New Files.mismatch方法”]添加Files.mismatch(Path,Path)方法“比較兩個文件的內容以確定它們之間是否存在不匹配”,并且可以用于確定“兩個文件是否相等”。 曾有一次添加File.isSameContent()方法的討論 ,但由于它與“ Arrays.mismatch和Buffer.mismatch方法”的一致性,因此決定使用Files.mismatch(Path,Parh) 。

下一個代碼清單包含一個簡單的Java類,該類演示了新的Files.mismatch(Path,Path)并將其與Files.isSameFile(Path,Path)進行對比。

package dustin.examples.jdk12.files;import java.nio.file.Files; import java.nio.file.Path;import static java.lang.System.out;/*** Demonstrate {@code Files.mismatch(Path,Path)} introduced with JDK 12* and useful for determining if two files have the same content even* if they're not the same files.*/ public class FilesDemo {public static void main(final String[] arguments) throws Exception{if (arguments.length < 2){out.println("USAGE: FilesDemo <file1Name> <file2Name>");return;}final String file1Name = arguments[0];final Path file1Path = Path.of(file1Name);final String file2Name = arguments[1];final Path file2Path = Path.of(file2Name);out.println("\nFiles '" + file1Name + "' and '" + file2Name + "' are "+ (Files.isSameFile(file1Path, file2Path) ? "the" : "NOT the")+ " same.\n\n");out.println("\nFiles '" + file1Name + "' and '" + file2Name + "' are "+ (Files.mismatch(file1Path, file2Path) == -1 ? "the" : "NOT the")+ " same content.\n\n");} }

當針對各種文件組合執行上述代碼時,它將提供在下表中捕獲的結果。

文件關系 Files.isSameFile(Path,Path) Files.mismatch(Path,Path)
同一文件 true true
復制的文件 false true
不同的文件 false false
軟鏈接 true true
硬連結 true true

添加Files.mismatch(Path,Path)是完成JDK-6852033 [“使常見的I / O任務更容易執行的輸入/輸出方法”]的又一個步驟,它使確定兩個不相同文件的時間變得更容易。相同文件仍然“相等”或具有相同內容。

翻譯自: https://www.javacodegeeks.com/2018/11/jdk-12s-files-mismatch-method.html

總結

以上是生活随笔為你收集整理的JDK 12的Files.mismatch方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。