Last active
December 10, 2015 06:39
-
-
Save madan712/4395954 to your computer and use it in GitHub Desktop.
Java - Get content type of a particular file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ContentTypeChecker.java */ | |
import java.io.File; | |
import java.io.IOException; | |
import java.net.URL; | |
import java.net.URLConnection; | |
public class ContentTypeChecker { | |
public static void main(String[] args) throws IOException { | |
File file = new File("C:/image.jpg"); | |
URL u = new URL("file:"+file); | |
URLConnection uc = u.openConnection(); | |
String type = uc.getContentType(); | |
System.out.println("Content type of file '"+file+"' is "+type); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment