Is it possible to get the name of a file downloaded with HttpURLConnection?
URL url = new URL(\"http://somesite/getFile?id=12345\");
HttpURLConnection conn =
Map map = connection.getHeaderFields ();
if ( map.get ( "Content-Disposition" ) != null )
{
String raw = map.get ( "Content-Disposition" ).toString ();
// raw = "attachment; filename=abc.jpg"
if ( raw != null && raw.indexOf ( "=" ) != -1 )
{
fileName = raw.split ( "=" )[1]; // getting value after '='
fileName = fileName.replaceAll ( "\"", "" ).replaceAll ( "]", "" );
}
}