Here you can find the source of combinePaths(String root, String... more)
Parameter | Description |
---|---|
root | - Root Path |
more | - Children to Append |
public static final String combinePaths(String root, String... more)
//package com.java2s; /*/*from ww w . jav a 2 s . co m*/ * Argus Installer v2 -- A Better School Zip Alternative Copyright (C) 2014 Matthew * Crocco * * This program is free software: you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this * program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; public class Main { /** * Similar to Paths.get(String, String...) in Java 7's NIO2 Package. <br /> * <br /> * This method will combine a root path with multiple children to create a <br /> * a single path with proper separator characters. * * @param root * - Root Path * @param more * - Children to Append * @return */ public static final String combinePaths(String root, String... more) { final StringBuilder sb = new StringBuilder(root); // Remove final separator if it exists to simplify appending if (root.endsWith("/") || root.endsWith("\\")) { sb.deleteCharAt(sb.length() - 1); } // Append Children to Root Path for (final String s : more) { sb.append(File.separator + s); } // Ensure Path Separator's are Homogeneous for (int i = 0; i < sb.length(); i++) { if ((sb.charAt(i) == '/') || (sb.charAt(i) == '\\')) { sb.setCharAt(i, File.separatorChar); } } return sb.toString(); } }