Here you can find the source of normalizePath(final String... path)
public static String normalizePath(final String... path)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Red Hat, Inc../*w w w . j a v a 2s . c om*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * Red Hat, Inc. - initial API and implementation ******************************************************************************/ public class Main { public static String normalizePath(final String... path) { if (path == null || path.length < 1) { return "/"; } final StringBuilder sb = new StringBuilder(); int idx = 0; parts: for (String part : path) { if (part == null || part.length() < 1 || "/".equals(part)) { continue parts; } if (idx == 0 && part.startsWith("file:")) { if (part.length() > 5) { sb.append(part.substring(5)); } continue parts; } if (idx > 0) { while (part.charAt(0) == '/') { if (part.length() < 2) { continue parts; } part = part.substring(1); } } while (part.charAt(part.length() - 1) == '/') { if (part.length() < 2) { continue parts; } part = part.substring(0, part.length() - 1); } if (sb.length() > 0) { sb.append('/'); } sb.append(part); idx++; } if (path[path.length - 1].endsWith("/")) { sb.append("/"); } return sb.toString(); } }