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两个文件夹比较路径

java两个文件夹比较路径_比较Java中两个文件的路径相关推荐

  1. netbeans缺少java文件夹_Java,如何在netbeans中添加库文件?

    在Netbeans 8.2中 1.从Web源下载二进制文件. 该阿帕奇Commos是:http://commons.apache.org/components.html][1] 在这种情况下,你必须选 ...

  2. aix查看文件夹大小命令_在aix中查看文件大小

    1.一个超级常用的命令; ls -l   --以长格式显示当前目录下的文件和目录 # ls -l total 152 drwxr-xr-x   2 oracle   dba             2 ...

  3. 如何修改was的java路径_在eclipse中修改tomcat的部署路径操作

    在eclipse上面部署web项目后,它没有将你的项目文件放到tomcat 的目录下面.而是放在了你的工作目录下面. 你到这里去找:E:\jintao\.metadata\.plugins\org.e ...

  4. python模糊查找文件夹名字_python实现在目录中查找指定文件的方法

    本文实例讲述了python实现在目录中查找指定文件的方法.分享给大家供大家参考.具体实现方法如下: 1. 模糊查找 复制代码 代码如下: import os from glob import glob ...

  5. win10计算机的六个文件夹,Windows10系统删除此电脑中6个文件夹的方法

    正常情况下,Windows10系统用户打开此电脑(我的电脑)的话,都会看到六个文件夹,分别是视频.图片.文档.下载.音乐.桌面.其实,这六个文件夹是非常方便的设置.不过,仍有一些用户表示并不喜欢它们, ...

  6. linux里如何创建c文件夹,使用c语言在Linux中的/ tmp文件夹中创建文本文件

    #include // Defines fopen(), fclose(), fprintf(), printf(), etc. #include // Defines errno C程序mkstem ...

  7. git中.ssh文件夹在哪_关于git中的https和ssh,权限等问题

    本地仓库和远程仓库通讯的两种方式:https和ssh 1.使用https通信: 公有仓库,用户B具有仓库A的克隆(只读)权限,没有push(修改)等权限:克隆时,用户B要输入自己的用户和密码进行身份识 ...

  8. python找不到指定的文件夹里_Python环球网在Unix中的指定文件路径中找不到*.txt

    我在Windows环境中写了一些文件,我在转换文件时遇到了麻烦.在Windows中,我通常使用类似以下内容读取目录中的所有.txt文件:pathtotxt = "C:\\Text Data\ ...

  9. 如何找到python的安装路径_在cmd中查看python的安装路径方法

    我相信一定有很多的人跟我一样,经常忘记Python安装的路径,每当用到的时候,最笨的办法就是在全局电脑里,直接查找Python,这样是肯定能查到的,但是如果你的电脑文件超级多,这将是一个工厂量很大的事 ...

  10. curl linux 批量下载文件夹,bash – 使用cURL下载目录中的所有文件

    好的,考虑到你使用的是Windows,最简单的方法就是使用与之捆绑的标准ftp工具.我将以下解决方案基于Windows XP,希望它在其他版本上也能正常工作(或稍作修改). 首先,您需要为ftp程序创 ...

最新文章

  1. php页头滚动文字公告,jQuery公告栏文字滚动插件
  2. sql server 2005 T-SQL ALTER ENDPOINT (Transact-SQL)
  3. 一个使用 SAP Spartacus 开发的电商网站 - Lego 乐高
  4. 一些sql 语句(行列转换等)
  5. 阿里的事前验尸_(不太完全)100天的代码-验尸
  6. React开发(183):ant design 中treeSelect控制选中
  7. 这几天都是在公司慢待
  8. vue-slicksort拖拽组件
  9. 时间都去哪儿了之Python程序测试与优化
  10. Fences报错,explorer.exe未正确关闭问题
  11. 存储卡修复软件测试自学,扩容内存卡用mydisktest失效,教你怎么用USBoot恢复出真实容量...
  12. 使用REG注册表文件添加、修改或删除注册表键值和子项介绍
  13. 网络文件存储系统(二)minio分布式文件系统实战
  14. Table sink ‘default_catalog.default_database.t3‘ doesn‘t support consuming update and delete changes
  15. numpy数组中元素单个选取或部分选取
  16. 以wifi为媒介,linux系统与android设备交互
  17. yolo imgaug数据增强 标签同时也增强
  18. window10怎么修改用户名以及C:/Users/后面的用户名
  19. 仪表板工具Stimulsoft Dashboards中的文本元素介绍
  20. 笔记本有时候能开机 有时候开不了

热门文章

  1. 毕业设计C语言网吧管理系统,毕业设计网吧管理系统.doc
  2. mysql主键和聚簇索引_[MySQL] innoDB引擎的主键与聚簇索引
  3. python 内置标准库socketserver模块的思考
  4. CSS中的overflow属性
  5. vue使用v-for循环,动态修改element-ui的el-switch
  6. 【Python 19】BMR计算器3.0(字符串分割与格式化输出)
  7. 关于常用的编码工具如何引入jar包
  8. 显示日历的指令:cal
  9. 题目1457:非常可乐(广度优先遍历BFS)
  10. 基于Maven的spring_security入门