Here you can find the source of mergePath(String path1, String path2)
Parameter | Description |
---|---|
path1 | in the head |
path2 | in the back |
public static String mergePath(String path1, String path2)
//package com.java2s; public class Main { /**//w ww.j av a 2 s .c o m * Merge two path to one path * * @param path1 in the head * @param path2 in the back * @return full path */ public static String mergePath(String path1, String path2) { String hp = path1 == null ? "" : path1; String hb = path2 == null ? "" : path2; String splider1 = ""; if (hp.endsWith("/") || hp.endsWith("\\")) { splider1 = hp.substring(hp.length() - 1, hp.length()); hp = hp.substring(0, hp.length() - 1); } if (hb.startsWith("/") || hb.startsWith("\\")) { splider1 = hb.substring(0, 1); hb = hb.substring(1, hb.length()); } if (splider1.length() == 0) { splider1 = "/"; } return hp + splider1 + hb; } }