java兩個文件夾比較路徑_比較Java中兩個文件的路徑

java兩個文件夾比較路徑

Given the paths of the two files and we have two compare the paths of the files in Java.

給定兩個文件的路徑,我們有兩個比較Java中文件的路徑。

Comparing paths of two files

比較兩個文件的路徑

To compare the paths of two files, we can use compareTo() method, it is called with a file object and second file path passes as an argument and method returns 0 if both file paths are the same.

為了比較兩個文件的路徑 ,我們可以使用compareTo()方法 ,該方法與文件對象一起調用,第二個文件路徑作為參數傳遞,并且如果兩個文件路徑相同,則方法返回0。

Syntax:

句法:

    //file object creation
File F1 = new File("d://courses//intro.docx");
File F2 = new File("d://courses//intro.docx");
//comparing file paths of F1 and F2
F1.compareTo(F2);
Output:
0

Java代碼比較兩個文件的路徑 (Java code to compare the paths of two files)

//Java code to compare the paths of two files
import java.io.*;
public class Main {
public static void main(String[] args) {
//file object creation
File F1 = new File("d://courses//intro.docx");
File F2 = new File("d://courses//intro.docx");
File F3 = new File("d://courses//basic.docx");
//comparing file paths using compareTo() method
//comparing file paths of F1 and F2
if (F1.compareTo(F2) == 0) {
System.out.println("paths of F1 and F2 are same...");
} else {
System.out.println("paths of F1 and F2 are not same...");
}
//comparing file paths of F2 and F3
if (F2.compareTo(F3) == 0) {
System.out.println("paths of F2 and F3 are same...");
} else {
System.out.println("paths of F2 and F3 are not same...");
}
//comparing file paths of F3 and F1
if (F3.compareTo(F1) == 0) {
System.out.println("paths of F3 and F1 are same...");
} else {
System.out.println("paths of F3 and F1 are not same...");
}
}
}

Output

輸出量

paths of F1 and F2 are same...
paths of F2 and F3 are not same...
paths of F3 and F1 are not same...

翻譯自: https://www.includehelp.com/java-programs/comparing-the-paths-of-the-two-files-in-java.aspx

java兩個文件夾比較路徑

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379523.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379523.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379523.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

標題:加法變乘法

標題:我們都知道:123 … 49 1225 現在要求你把其中兩個不相鄰的加號變成乘號,使得結果為2015 比如: 123…10*1112…27*2829…49 2015 就是符合要求的答案。 請你尋找另外一個可能的答案,并把位置靠前的那個乘號左…

C# winform對話框用法大全收藏

對話框中我們常用了以下幾種: 1、文件對話框(FileDialog) 它又常用到兩個: 打開文件對話框(OpenFileDialog) 保存文件對話(SaveFileDialog) 2、字體對話框(FontDialog) 3、顏色對話框(ColorDialog) 4、打印預瀏對話框(PrintPreviewDialog) 5、…

【翻譯】eXpressAppFramework QuickStart 業務模型設計(四)—— 實現自定義業務類...

這一講,你將學到如何從頭開始實現業務類。為此,將要實現Department和Position業務類。這些類將被應用到之前實現的Contact類中。你將學到引用對象自動生成用戶界面的基本要素。 在此之前,我建議你去閱讀一下 【翻譯】eXpressAppFramework Qui…

內存重映射

文章目錄1 kmap2 映射內核內存到用戶空間使用remap_pfn_range使用io_remap_pfn_rangemmap文件操作建立VMA和實際物理地址的映射mmap 之前分配 一次性映射mmap 之前分配 Page FaultPage Fault 中分配 映射內核內存有時需要重新映射,無論是從內核到用戶空間還是從內…

math.sqrt 有問題_JavaScript中帶有示例的Math.sqrt()方法

math.sqrt 有問題JavaScript | Math.sqrt()方法 (JavaScript | Math.sqrt() Method) The Math.sqrt() method is inbuilt in JavaScript to find the square root of a number. In this tutorial, we will learn about the sqrt() method with examples. JavaScript中內置了Mat…

標題:移動距離

標題:移動距離 X星球居民小區的樓房全是一樣的,并且按矩陣樣式排列。其樓房的編號為1,2,3… 當排滿一行時,從下一行相鄰的樓往反方向排號。 比如:當小區排號寬度為6時,開始情形如下: 1 2 3 4 5 6 12 11 1…

ISAPI Rewrite 實現簡單url重寫、二級域名重寫

實現步驟: 第一步:下載ISAPI_Rewrite.rar,將Rewrite文件夾和httpd.ini直接放在項目根目錄下面。 第二步:IIS配置,篩選Rewrite文件夾里面的Rewrite.dll文件,如圖: 第三步:在httpd.ini…

用戶登錄

用戶登錄 代碼namespace 用戶登錄 {public partial class Form1 : Form{public Form1(){InitializeComponent();}bool b1, b2, b3, b4, b5, b6;private void button1_Click(object sender, EventArgs e){try{if (b1 && b2 && b3 && b4 && b5 &…

進程上下文和中斷上下文

文章目錄進程的preempt_count變量thread_infopreempt_counthardirq相關softirq相關上下文原文鏈接: https://zhuanlan.zhihu.com/p/88883239進程的preempt_count變量 thread_info 在內核中,上下文的設置和判斷接口可以參考 include/linux/preempt.h 文…

標題:湊算式

標題:湊算式 這個算式中AI代表19的數字,不同的字母代表不同的數字。 比如: 68/3952/714 就是一種解法, 53/1972/486 是另一種解法。 這個算式一共有多少種解法? 注意:你提交應該是個整數,不要…

匯編中imul_JavaScript中帶有示例的Math.imul()方法

匯編中imulJavaScript | Math.imul()方法 (JavaScript | Math.imul() Method) Math.imul() is a function in math library of JavaScript that is used to the 32-bit multiplication of the two values passed to it. It uses C-like semantics to find the multiplication. …

AFTER觸發器與INSTEAD OF觸發器的區別

INSTEAD OF 觸發器用來代替通常的觸發動作,即當對表進行INSERT、UPDATE 或 DELETE 操作時,系統不是直接對表執行這些操作,而是把操作內容交給觸發器,讓觸發器檢查所進行的操作是否正確。如正確才進行相應的操作。因此,…

Linux內存地址管理

文章目錄系統內存布局內核地址的低端和高端內存概念低端內存高端內存地址轉換和MMULinux中的四級分頁模型虛擬地址字段頁表處理將虛擬地址轉換物理地址Linux系統中的每個內存地址都是虛擬的,它們不直接指向任何物理內存地址。每當訪問內存位置時,可以執行…

錄制caf 轉 mp3

編譯需要使用的 lame庫http://www.cocoachina.com/bbs/read.php?tid108237參考的文章http://blog.csdn.net/ysy441088327/article/details/7392842說起來,我一直在找一個音頻轉換成mp3的方法。一年前,我成功編譯出了一個lame for armv7的庫。苦于不會使…

杭電2012-素數判定(C)

Problem Description 對于表達式n^2n41&#xff0c;當n在&#xff08;x,y&#xff09;范圍內取整數值時&#xff08;包括x,y&#xff09;(-39<x<y<50)&#xff0c;判定該表達式的值是否都為素數。 Input 輸入數據有多組&#xff0c;每組占一行&#xff0c;由兩個整數…

math.ceil帶小數點_JavaScript中帶有示例的Math.ceil()方法

math.ceil帶小數點JavaScript | Math.ceil()方法 (JavaScript | Math.ceil() Method) Math.ceil() is a function in math library of JavaScript that is used to round up the number passed to the function. The method will return the nearest integer value indeed is g…

開發記要 詭異的變量

告別繁體文盲,從寫blog開始 Variable命名很重要,有多重要,看看.net和java的加密就知道, 都是把variable改到一塌糊塗,你想看看都沒門. 但是這幾天看遺留系統的代碼,真是大開眼界。 我一直以為別人寫a,b,c,d這些單字節variable已經很過分。直到我看到以下這幾個&#xff0…

排序算法---快速排序、堆排序、冒泡排序

排序算法1 快速排序代碼實現stdlib庫快排2 堆排序堆排序的基本思想如何構造一個大頂堆排序3 冒泡排序1 快速排序 文章原地址&#xff1a;https://blog.csdn.net/morewindows/article/details/6684558 快速排序的平均時間復雜度是0(NlogN)&#xff0c;它采用了一種分治的策略&a…

CSS Hack 匯總快查

*:lang(zh) select {font:12px !important;} /*FF的專用*/ select:empty {font:12px !important;} /*safari可見*/ 這里select是選擇符&#xff0c;根據情況更換。第二句是MAC上safari瀏覽器獨有的。 僅IE7識別 *html {…} 當面臨需要只針對IE7做樣式的時候就可以采用這個HACK…

杭電2013-蟠桃記(C++)

Problem Description 喜歡西游記的同學肯定都知道悟空偷吃蟠桃的故事&#xff0c;你們一定都覺得這猴子太鬧騰了&#xff0c;其實你們是有所不知&#xff1a;悟空是在研究一個數學問題&#xff01; 什么問題&#xff1f;他研究的問題是蟠桃一共有多少個&#xff01; 不過&#…