Java tutorial
//package com.java2s; 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); } else { return null; } } }