java后端获取当前页面的url,java 获取接口的所有子类

首页 > 教育培训 > 作者:YD1662023-05-10 13:03:42

1、使用 java.io.File

String path = "src/java/resources"; File file = new File(path); System.out.println("url: " file.toURI().toURL().toString());

输出结果:

url: file:/D:/03-project/html-to-pdf-demo/src/main/resources/2、使用 java.nio.file.Path

Path resourceDirectory = Paths.get("src","main","resources"); System.out.println("url: " resourceDirectory.toUri().toURL().toString());

输出结果:

url: file:/D:/03-project/html-to-pdf-demo/src/main/resources/3、使用 java.nio.file.FileSystems

String baseUrl = FileSystems .getDefault() .getPath("src", "main", "resources") .toUri() .toURL() .toString(); System.out.println("url: " baseUrl);

输出结果:

url: file:/D:/03-project/html-to-pdf-demo/src/main/resources/总结

从代码量上来看,使用 java.nio.file.Path 应该是最简洁干净的方式。

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.