PIPIONE
自从乔恩(Jon)的原始答案以来,我就已经知道了很长时间,但是我对OP有类似的要求。通过扩展Jon的解决方案,我提出了以下内容,它将采用一个或多个路径段,而您可以将其扔给它。用法Path.combine("/Users/beardtwizzle/");Path.combine("/", "Users", "beardtwizzle");Path.combine(new String[] { "/", "Users", "beardtwizzle", "arrayUsage" });在这里为其他有类似问题的人编码public class Path { public static String combine(String... paths) { File file = new File(paths[0]); for (int i = 1; i < paths.length ; i++) { file = new File(file, paths[i]); } return file.getPath(); }}