提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取路径文件/目录名称
import java.nio.file.Path; import java.nio.file.Paths; /** 来 自 NowJava.com - 时代Java **/ public class Main { public static void main(String[] args) { Path path = Paths.get("C:", "folder1/folder2/folder4", "test.txt"); System.out.println("The file/directory indicated by path: " + path.getFileName()); } }