Does Java have a path joining method? [duplicate] Does Java have a path joining method? [duplicate] java java

Does Java have a path joining method? [duplicate]


This concerns Java versions 7 and earlier.

To quote a good answer to the same question:

If you want it back as a string later, you can call getPath(). Indeed, if you really wanted to mimic Path.Combine, you could just write something like:

public static String combine (String path1, String path2) {    File file1 = new File(path1);    File file2 = new File(file1, path2);    return file2.getPath();}


Try:

String path1 = "path1";String path2 = "path2";String joinedPath = new File(path1, path2).toString();


One way is to get system properties that give you the path separator for the operating system, this tutorial explains how. You can then use a standard string join using the file.separator.