Here you can find the source of buildPath(String first, String... parts)
Parameter | Description |
---|---|
first | the first part. |
parts | the additional parts. |
public static String buildPath(String first, String... parts)
//package com.java2s; /**/*from w ww. ja v a 2 s. c o m*/ * Copyright (c) 2013-2016, The SeedStack authors <http://seedstack.org> * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ public class Main { /** * Concatenate path parts into a full path, taking care of extra or missing slashes. * * @param first the first part. * @param parts the additional parts. * @return the concatenated path. */ public static String buildPath(String first, String... parts) { String result = first; for (String part : parts) { if (result.isEmpty()) { if (part.startsWith("/")) { result += part.substring(1); } else { result += part; } } else { if (result.endsWith("/") && part.startsWith("/")) { result += part.substring(1); } else if (!result.endsWith("/") && !part.startsWith("/") && !part.isEmpty()) { result += "/" + part; } else { result += part; } } } return result; } }