Java URL to File Name getFileName(HttpURLConnection conn)

Here you can find the source of getFileName(HttpURLConnection conn)

Description

get File Name

License

Apache License

Declaration

private static String getFileName(HttpURLConnection conn) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.HttpURLConnection;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static final Pattern REGEX_FILE_NAME = Pattern.compile("attachment;filename=\"([\\w\\-]+)\"");

    private static String getFileName(HttpURLConnection conn) {
        String fileName = conn.getHeaderField("Content-Disposition");
        Matcher matcher = REGEX_FILE_NAME.matcher(fileName);
        if (matcher.find()) {
            return matcher.group(1);
        }//from  w  w  w .  j a va2 s.co  m
        return null;
    }
}

Related

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