Here you can find the source of toURI(URI parent, String child)
Parameter | Description |
---|---|
parent | the URI to parent directory |
child | the child name |
public static URI toURI(URI parent, String child)
//package com.java2s; // This software is released under the GNU General Public License. // import java.net.URI; import java.net.URISyntaxException; public class Main { /**/*from w ww. j ava2s. com*/ * Convenient method to simulate a parent/child composition * * @param parent the URI to parent directory * @param child the child name * @return the resulting URI */ public static URI toURI(URI parent, String child) { try { // Make sure parent ends with a '/' if (parent == null) { throw new IllegalArgumentException("Parent is null"); } StringBuilder dirName = new StringBuilder(parent.toString()); if (dirName.charAt(dirName.length() - 1) != '/') { dirName.append('/'); } // Make sure child does not start with a '/' if ((child == null) || child.isEmpty()) { throw new IllegalArgumentException("Child is null or empty"); } if (child.startsWith("/")) { throw new IllegalArgumentException("Child is absolute: " + child); } return new URI(dirName.append(child).toString()); } catch (URISyntaxException ex) { throw new IllegalArgumentException(ex.getMessage(), ex); } } }