If you use Java 7 or 8, you can use java.nio.file.Path. Path.resolve is used to merge one path with another. Paths classes are also useful.
Path path = Paths.get("foo", "bar", "baz.txt");
You can use it like this.
If you're using an earlier version of Java7, you can do this at java.io.File.
File baseDirectory = new File("foo");
File subDirectory = new File(baseDirectory, "bar");
File fileInDirectory = new File(subDirectory, "baz.txt");
If you want to receive it as a string, use getPath()
public static String combine(String path1, String path2)
{
File file1 = new File(path1);
File file2 = new File(file1, path2);
return file2.getPath();
}
You can do it like this.
© 2024 OneMinuteCode. All rights reserved.