Java 实例 - 文件路径比较

Java 教程 · 2019-02-10 23:26:22

以下实例演示了使用 File 类的 filename.compareTo (another filename) 方法来比较两个文件路径是否在同一个目录下:

Main.java 文件

import java.io.File; public class Main { public static void main(String[] args) { File file1 = new File("C:/File/demo1.txt"); File file2 = new File("C:/java/demo1.txt"); if(file1.compareTo(file2) == 0) { System.out.println("文件路径一致!"); } else { System.out.println("文件路径不一致!"); } } }

以上代码运行输出结果为:

文件路径不一致!

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

Algorithms Sequential & Parallel

Algorithms Sequential & Parallel

Russ Miller、Laurence Boxer / Charles River Media / 2005-08-03 / USD 59.95

With multi-core processors replacing traditional processors and the movement to multiprocessor workstations and servers, parallel computing has moved from a specialty area to the core of computer scie......一起来看看 《Algorithms Sequential & Parallel》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具