Using Java 7 import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Test { public static void main(String[] args) throws IOException { Path source = Paths.get("c:/temp/0multipage.tif"); System.out.println(Files.probeContentType(source)); // output : image/tiff } } The default implementation is OS-specific and not very complete. It's possible to register a better detector, like for example Apache Tika, see Transparently improve Java 7 mime-type recognition with Apache Tika . Using javax.activation.
Read full article from Get the Mime Type from a File - Real's Java How-to
No comments:
Post a Comment