java中通过文件路径获取文件名时间:2025-01-15 14:36:04代码: import ; public class Test { public static void main(String[] args) { // path String path1 = "D:/folder1/folder2/folder3/"; String path2 = "/folder2/folder3/"; // file File file1 = new File(path1); File file2 = new File(path2); // get name of file String fileName1 = (); String fileName2 = (); // print file name ("1 ---> " + fileName1); ("2 ---> " + fileName2); } } 结果: //1 ---> //2 --->