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://www.codercto.com/courses/l/12.html
Algorithms in C++
Robert Sedgewick / Addison-Wesley Professional / 1992-05-10 / USD 64.99
This version of Sedgewick's bestselling book provides a comprehensive collection of algorithms implemented in C++. The algorithms included cover a broad range of fundamental and more advanced methods:......一起来看看 《Algorithms in C++》 这本书的介绍吧!