Java Utililty Methods URL to File Name

List of utility methods to do URL to File Name

Description

The list of methods to do URL to File Name are organized into topic(s).

Method

StringgetFileName(URLConnection urlC)
Returns the file name associated to an url connection.
The result is not a path but just a file name.
String fileName = null;
String contentDisposition = urlC.getHeaderField("content-disposition");
if (contentDisposition != null) {
    fileName = extractFileNameFromContentDisposition(contentDisposition);
if (fileName == null) {
    StringTokenizer st = new StringTokenizer(urlC.getURL().getFile(), "/");
    while (st.hasMoreTokens())
...
StringgetFileName2(String url)
get File Name
String file = null;
try {
    file = (new File((new URI(url)).getPath())).getName();
    System.out.println("File name: " + file);
} catch (Exception var3) {
    ;
if (file == null || file.length() < 1) {
...
String[]getFileNameArray(String url)
get the correct name/extension/filename of url (even with parameters!
String[] ret = new String[] { "", "", "" };
String filename = "";
String path = "";
try {
    url = getURIEncoded(url).toString();
    path = new URL(url).getPath();
} catch (Exception e) {
    return ret;
...
StringgetFileNameFromContentDisposition(URLConnection connection)
get File Name From Content Disposition
String contentDispositionHeaderValue = connection.getHeaderField(CONTENT_DISPOSITION_HEADER);
if (contentDispositionHeaderValue != null) {
    Matcher matcher = CONTENT_DISPOSITION_FILE_NAME_PATTERN.matcher(contentDispositionHeaderValue);
    if (matcher.matches()) {
        return matcher.group(CONTENT_DISPOSITION_FILE_NAME_PATTERN_GROUP);
return null;
...
StringgetFileNameFromUrl(URL inputUrl)
get File Name From Url
String urlStr = inputUrl.toString();
String fileName = urlStr.substring(urlStr.lastIndexOf("/") + 1);
return fileName;
StringgetFileNameFromUrl(URL inputUrl)
get File Name From Url
String urlStr = inputUrl.toString();
String fileName = urlStr.substring(urlStr.lastIndexOf("/") + 1);
return fileName;
StringURIToFilename(String str)
Fixes a platform dependent filename to standard URI form.
if (str.length() >= 3) {
    if (str.charAt(0) == '/' && str.charAt(2) == ':') {
        char ch1 = Character.toUpperCase(str.charAt(1));
        if (ch1 >= 'A' && ch1 <= 'Z')
            str = str.substring(1);
str = str.replace('/', java.io.File.separatorChar);
...