Here you can find the source of concatPath(String pathName, String name)
public static String concatPath(String pathName, String name)
//package com.java2s; //License from project: Apache License public class Main { /**//from www. j ava 2 s . c o m * Concatenates specified path with name, and makes sure that only one * path-separator is added. Examples: "/path1/" + "/name1" --> * "/path1/name1", "/path2" + "name2" --> "path1/name1". */ public static String concatPath(String pathName, String name) { // param-check if ((pathName == null) || (pathName.length() == 0)) { return name; } if ((name == null) || (name.length() == 0)) { return pathName; } StringBuffer result = new StringBuffer(160); if (pathName.endsWith("/")) { if (name.startsWith("/")) { // remove "/" result.append(pathName.substring(0, pathName.length() - 1)); } else { result.append(pathName); } } else { result.append(pathName); if (!name.startsWith("/")) { // add "/" result.append("/"); } } result.append(name); return result.toString(); } }