Java Path Combine combinePaths(String... items)

Here you can find the source of combinePaths(String... items)

Description

Simplifies the way to combine paths.

License

Open Source License

Declaration

public static String combinePaths(String... items) 

Method Source Code

//package com.java2s;

public class Main {
    /** Simplifies the way to combine paths. Takes care about normalization. */
    public static String combinePaths(String... items) {
        if (items.length == 0) {
            return "";
        }//  w  ww  .  j  ava2 s.c o m

        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();
    }
}

Related

  1. combinePath(String... paths)
  2. combinePath(String... paths)
  3. combinePaths(final String path, final String... furtherPaths)
  4. combinePaths(String root, String... more)
  5. combinePaths(String root, String... more)
  6. combinePaths(String[] paths)