Here you can find the source of getContentTypeFromUrl(String urlname)
public static String getContentTypeFromUrl(String urlname) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static String getContentTypeFromUrl(String urlname) throws IOException { URL url = new URL(urlname); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); try {/*from w w w. j ava 2 s .c o m*/ connection.setRequestMethod("HEAD"); connection.connect(); return connection.getContentType(); } finally { connection.disconnect(); } } }