Skip to content

Instantly share code, notes, and snippets.

@marius92mc
Created April 19, 2015 15:03
Show Gist options
  • Save marius92mc/0c01f0ec397a19617cf5 to your computer and use it in GitHub Desktop.
Save marius92mc/0c01f0ec397a19617cf5 to your computer and use it in GitHub Desktop.
public static String documentType(String file)
{
String fileType = "Undetermined";
try
{
final URL url = new URL("file://" + file);
final URLConnection connection = url.openConnection();
fileType = connection.getContentType();
}
catch (MalformedURLException badUrlEx)
{
System.out.println("ERROR: Bad URL - " + badUrlEx);
}
catch (IOException ioEx)
{
System.out.println("Cannot access URLConnection - " + ioEx);
}
return fileType;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment