code
code

Reputation: 55

How to check if a URL is a Doc or a web page using java

I'm buliding an application similar to a URL crawler wherein I need differentiate between a normal webpage and a pdf or img or doc. Tried all ways of MIMETYPE checks... :(

Upvotes: 1

Views: 1251

Answers (1)

omerfarukdogan
omerfarukdogan

Reputation: 869

That will do the job:

URL url = new URL(adress);
URLConnection u = url.openConnection();
String type = u.getHeaderField("Content-Type");
return type;

Returns

text/html; charset=utf-8

for this page.

Upvotes: 1

Related Questions