Java URI Create getURI(String path, String name)

Here you can find the source of getURI(String path, String name)

Description

Return a URI object for a filename with the given path

License

Open Source License

Parameter

Parameter Description
name Name of file
path Path to file

Return

URI object for named file

Declaration

public static URI getURI(String path, String name) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.URI;

public class Main {
    /**//  ww  w .j a  v a2  s.c  om
     * Return a URI object for a filename with the given path
     * 
     * @param name
     *          Name of file
     * @param path
     *          Path to file
     * 
     * @return URI object for named file
     * 
     * @exception dException
     *              something went wrong creating the URI.
     */
    public static URI getURI(String path, String name) throws Exception {
        URI uri;
        // construct a URI from a path and string
        try {
            String URIstr = path + "/" + name;

            // replace any spaces with %20;
            while (URIstr.indexOf(' ') > 0) {
                int spcLoc = URIstr.indexOf(' ');
                StringBuffer sb = new StringBuffer(URIstr);
                sb.replace(spcLoc, spcLoc + 1, "%20");
                URIstr = new String(sb);
            }
            uri = new URI(URIstr);
        } catch (Exception ex) {
            System.out.println("malformed URI");
            ex.printStackTrace();
            throw ex;
        }
        return uri;
    }
}

Related

  1. getURI(String bucket, String key)
  2. getURI(String host, int port, String path, boolean isHTTPS)
  3. GetURI(String host, String port, String resource)
  4. getURI(String path)
  5. getURI(String path)
  6. getURI(String protocol, String authority, String path, Hashtable params)
  7. getUri(String s, String h, int p, String path)
  8. getURI(String spec)
  9. getUri(String uriName)