完全重复:
我想知道Java中是否有这样的方法。以此片段为例:
// this will output a/b
System.out.println(path_join("a","b"));
// a/b
System.out.println(path_join("a","/b");
最佳答案
这涉及 Java 版本 7 及更早版本。
引用 good answer to the same question :
如果您希望稍后将其作为字符串返回,您可以调用 getPath()。事实上,如果你真的想模仿 Path.Combine,你可以写这样的东西:
public static String combine (String path1, String path2) {
File file1 = new File(path1);
File file2 = new File(file1, path2);
return file2.getPath();
}
关于java - Java有路径连接方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/711993/