Java Utililty Methods Path Combine

List of utility methods to do Path Combine

Description

The list of methods to do Path Combine are organized into topic(s).

Method

StringcombinePath(String path1, String path2, String pathSeperator)
combine Path
String path = null;
if (pathSeperator == null || pathSeperator.trim().equals("")) {
    pathSeperator = File.separator;
if (path1 != null && path2 != null) {
    path1 = path1.trim();
    path2 = path2.trim();
    if (path1.equals(""))
...
StringcombinePath(String... paths)
combine Path
StringBuffer sb = new StringBuffer();
for (String x : paths) {
    x = x.replace("\\", "/");
    if (sb.length() == 0) {
        sb.append(x);
    } else {
        char last = sb.charAt(sb.length() - 1);
        if (x.startsWith("/")) {
...
StringcombinePath(String... paths)
Combine the arguments into a complete file path
File file = new File(paths[0]);
for (int i = 1; i < paths.length; i++) {
    file = new File(file, paths[i]);
return file.getPath();
StringcombinePaths(final String path, final String... furtherPaths)
combine Paths
final StringBuilder buf = new StringBuilder(path);
for (final String furtherPath : furtherPaths) {
    if (buf.charAt(buf.length() - 1) != File.separatorChar) {
        buf.append(File.separatorChar);
    buf.append(furtherPath);
return buf.toString();
...
StringcombinePaths(String root, String... more)
combine Paths
StringBuilder sb = new StringBuilder(root);
String sep = File.separator;
if (root.endsWith("/") || root.endsWith("\\")) {
    sb.deleteCharAt(sb.length() - 1);
for (String s : more) {
    sb.append(sep + s);
return sb.toString();
StringcombinePaths(String root, String... more)
Similar to Paths.get(String, String...) in Java 7's NIO2 Package.
final StringBuilder sb = new StringBuilder(root);
if (root.endsWith("/") || root.endsWith("\\")) {
    sb.deleteCharAt(sb.length() - 1);
for (final String s : more) {
    sb.append(File.separator + s);
for (int i = 0; i < sb.length(); i++) {
...
StringcombinePaths(String... items)
Simplifies the way to combine paths.
if (items.length == 0) {
    return "";
StringBuilder sb = new StringBuilder(items[0]);
for (int i = 1; i < items.length; i++) {
    if (!items[i - 1].endsWith("/")) {
        sb.append("/");
    if (items[i].startsWith("/")) {
        sb.append(items[i].substring(1));
    } else {
        sb.append(items[i]);
return sb.toString();
StringcombinePaths(String[] paths)
combine Paths
if (paths.length == 0) {
    return "";
File combined = new File(paths[0]);
int i = 1;
while (i < paths.length) {
    combined = new File(combined, paths[i]);
    ++i;
...