In Python
I can join two paths with os.path.join
:
os.path.join(\"foo\", \"bar\") # => \"foo/bar\"
I\'m trying to
Not an specific method.
If you use java 8 or better, you have 2 options:
a) Use java.util.StringJoiner
StringJoiner joiner = new StringJoiner(File.pathSeparator); //Separator
joiner.add("path1").add("path2");
String joinedString = joiner.toString();
b) Use String.join(File.pathSeparator, "path1", "path2");
If you use java 7 or lower, you may use commons-lang library from apache commons. The class StringUtils has a method to join strings using a separator.
c) StringUtils.join(new Object[] {"path1", "path2"}, File.pathSeparator);
A sidenote: You may use linux pathseparator "/" for windows (Just remember that absolute paths are something like "/C:/mydir1/mydir2". Using always "/" is very useful if you use protocols such as file://