Java URLConnection .guessContentTypeFromStream (InputStream is)
Syntax
URLConnection.guessContentTypeFromStream(InputStream is) has the following syntax.
public static String guessContentTypeFromStream(InputStream is) throws IOException
Example
In the following code shows how to use URLConnection.guessContentTypeFromStream(InputStream is) method.
import java.net.URL;
import java.net.URLConnection;
/*from w ww. j a v a 2 s .co m*/
public class Main{
public static void main(String args[]) throws Exception {
URL url = new URL("http://www.google.com");
URLConnection httpCon = (URLConnection) url.openConnection();
System.out.println(URLConnection.guessContentTypeFromStream(httpCon.getInputStream()));
}
}
The code above generates the following result.