Here you can find the source of joinPath(String part1, String part2)
public static String joinPath(String part1, String part2)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static String joinPath(String part1, String part2) { final List<String> parts = new ArrayList<>(); addPathPart(parts, part1);/* ww w . j a v a 2 s.c o m*/ addPathPart(parts, part2); return join(parts, "/"); } private static void addPathPart(List<String> parts, String part) { if (part != null) { final String trimmed = trimSlash(part); if (!trimmed.isEmpty()) { parts.add(trimmed); } } } public static String join(Iterable<? extends Object> values, String delimiter) { final StringBuilder sb = new StringBuilder(); boolean first = true; for (Object value : values) { if (first) { first = false; } else { sb.append(delimiter); } sb.append(value); } return sb.toString(); } private static String trimSlash(String path) { path = path.startsWith("/") ? path.substring(1) : path; path = path.endsWith("/") ? path.substring(0, path.length() - 1) : path; return path; } }