Java URI to File Name getFileName(URI uri)

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

Description

Extract the file-name portion of a URI.

License

Apache License

Parameter

Parameter Description
uri the URI to be processed

Return

the file-name portion of the URI

Declaration

public static String getFileName(URI uri) 

Method Source Code

//package com.java2s;
/*/* w w w. j  av a 2 s  .c o m*/
 *    Copyright 2010-2012 University of Toronto
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

import java.net.URI;

public class Main {
    /**
     * Extract the file-name portion of a URI.
     *
     * @param uri the URI to be processed
     * @return the file-name portion of the URI
     */
    public static String getFileName(URI uri) {
        String path = uri.toString();
        int lastSlashIndex = path.lastIndexOf("/");
        return path.substring(lastSlashIndex + 1, path.length());
    }
}

Related

  1. getFileByPathOrURI(String path)
  2. getFileFromURIList(URI[] uris, String fileName)
  3. getFilename(final URI uri)
  4. getFilename(final URI uri)
  5. getFileName(URI path)
  6. getFileName(URI uri)
  7. getFileName(URI uri)
  8. getFileName(URI uri)
  9. getFileNameFromURI(final URI resourceAddress, final boolean usePathStyleUris)