В Java 7 теперь вы можете просто использовать Files.probeContentType(path) .
Files.probeContentType(path)