提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从相对路径获得绝对路径。
import java.nio.file.Path; import java.nio.file.Paths; public class Main { /* 来 自* 时代Java公众号 - nowjava.com */ public static void main(String[] args) { Path path = Paths.get("/folder1/folder2/folder4", "test.txt"); //convert relative path to absolute path Path path_to_absolute_path = path.toAbsolutePath(); System.out.println("Path to absolute path: " + path_to_absolute_path.toString()); } }/* from n o w j a v a . c o m - 时 代 Java*/