提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用compareTo()方法比较路径,该方法按字典顺序比较两个抽象路径。
import java.nio.file.Path; import java.nio.file.Paths; /* n o w j a v a . c o m - 时代Java 提供 */ public class Main { public static void main(String[] args) { Path path01 = Paths.get("/folder1/folder2/folder3/test.txt"); Path path02 = Paths.get("C:/folder1/folder2/folder3/test.txt"); //compare using Path.compareTo int compare = path01.compareTo(path02); System.out.println(compare); }/** N o w J a v a . c o m - 时 代 Java 提供 **/ }