Java URL to File Name getFilename(final URL url, int maxLength)

Here you can find the source of getFilename(final URL url, int maxLength)

Description

get Filename

License

Open Source License

Declaration

public static String getFilename(final URL url, int maxLength) throws Exception 

Method Source Code


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

import java.net.URL;

public class Main {
    public static String getFilename(final URL url, int maxLength) throws Exception {
        String filename = url.toString();

        int index = filename.lastIndexOf('/');
        if (index >= 0) {
            filename = filename.substring(index + 1);
        }//from   ww  w .jav  a2s  .  co  m

        if (maxLength > 0 && filename.length() > maxLength) {
            filename = filename.substring(filename.length() - maxLength);
        }
        return filename;
    }

    public static String getFilename(final URL url) throws Exception {
        return getFilename(url, -1);
    }
}

Related

  1. getFileFromUrl(URL url)
  2. getFileFromURL(URL urlToDecode)
  3. getFileName(final CharSequence url)
  4. getFileName(final URL url)
  5. getFilename(final URL url)
  6. getFileName(HttpURLConnection conn)
  7. getFileName(String urlStr)
  8. getFilename(String urlString)
  9. getFileName(String urlString)