Java URI to File Name getFilePart(String uri)

Here you can find the source of getFilePart(String uri)

Description

get File Part

License

Open Source License

Declaration

public static String getFilePart(String uri) 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

import java.net.URI;

public class Main {
    public static String getFilePart(String uri) {
        try {//  w w  w  . j a v a 2  s. c  o m
            URI u = URI.create(uri);
            uri = u.getPath();
        } catch (Exception e) {
            return "http://invalid/uri/";
        }

        //if(uri.length() == 0) return
        int begin = uri.lastIndexOf("/");
        int end = uri.lastIndexOf(".");

        if (end == -1 || begin > end)
            end = uri.length();

        return uri.substring(begin + 1, end);
    }
}

Related

  1. getFileName(URI uri)
  2. getFileName(URI uri)
  3. getFileName(URI uri)
  4. getFileNameFromURI(final URI resourceAddress, final boolean usePathStyleUris)
  5. getFilenameFromURI(URI uri, boolean preserveExtension)
  6. getFileSystemURI(URI uri)