Is there a way to generate a Content-Type header from a file extension in Java?

I have a Java application that sometimes needs to generate a Content-Type header from a single file name. Is there a way to evaluate Content-Type for common extensions? (for example, ".pdf" displays "application / pdf", etc.)

+3
source share
3 answers
+6
source

Yes, through the JavaBeans Activation Framework (javax.activation).

import java.io.File;
import javax.activation.MimetypesFileTypeMap;
...
return new MimetypesFileTypeMap().getContentType(new File("brognitz.jpg"));

, Java .

: , .

+6

A hash table that you loaded using generic types ?

0
source

Source: https://habr.com/ru/post/1721227/


All Articles