Here you can find the source of getFileNameFromContentDisposition(URLConnection connection)
private static String getFileNameFromContentDisposition(URLConnection connection)
//package com.java2s; //License from project: Open Source License import java.net.URLConnection; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static final String CONTENT_DISPOSITION_HEADER = "Content-Disposition"; private static final Pattern CONTENT_DISPOSITION_FILE_NAME_PATTERN = Pattern .compile(".*filename=\"([^\\s;]*)\".*"); private static final int CONTENT_DISPOSITION_FILE_NAME_PATTERN_GROUP = 1; private static String getFileNameFromContentDisposition(URLConnection connection) { 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); }/*from w ww .j a va2 s. c o m*/ } return null; } }