Java URI to Local Name getName(URI uri)

Here you can find the source of getName(URI uri)

Description

Returns the name of the file that is pointed to by this URI.

License

Open Source License

Parameter

Parameter Description
uri the uri to get the name for.

Return

the name of the file.

Declaration

public static String getName(URI uri) 

Method Source Code

//package com.java2s;

import java.net.URI;

public class Main {
    /**//  ww  w.j  a  v a  2 s.  com
     * Returns the name of the file that is pointed to by this URI.
     *
     * @param uri the uri to get the name for.
     *
     * @return the name of the file.
     */
    public static String getName(URI uri) {
        if (uri != null) {
            String location = uri.getSchemeSpecificPart();
            if (location != null) {
                String name = location;
                int index = location.lastIndexOf('/');
                if (index != -1) {
                    name = name.substring(index + 1, name.length());
                }
                return name;
            }
        }
        return "";
    }
}

Related

  1. getLocalName(String uri)
  2. getLocalName(URI uri)
  3. getLocalName(URI uri)
  4. getLocalPart(String uri)
  5. getName(URI uri)
  6. getName(URI uri)
  7. getName(URI uri)
  8. getName(URI uri)
  9. getName(URI uri)