Java URL to File Name getFileName(String urlString)

Here you can find the source of getFileName(String urlString)

Description

get File Name

License

Apache License

Declaration

public static String getFileName(String urlString) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2013 EMBL-EBI// w ww  .j a v a 2s  .co  m
 *
 * 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.io.File;

import java.net.MalformedURLException;

import java.net.URL;

public class Main {
    public static String getFileName(String urlString) {
        URL url = null;
        try {
            url = new URL(urlString);
            return new File(url.getFile()).getName();
        } catch (MalformedURLException e) {
            return new File(urlString).getName();
        }
    }
}

Related

  1. getFilename(final URL url)
  2. getFileName(final URL url)
  3. getFilename(final URL url, int maxLength)
  4. getFileName(HttpURLConnection conn)
  5. getFileName(String urlStr)
  6. getFilename(String urlString)
  7. getFileName(URL extUrl)
  8. getFileName(URL url)
  9. getFileName(URL url)