URLConnection.guessContentTypeFromName doesn't seem to work with csv extension

Viewed 116

I have been using URLConnection.guessContentTypeFromName(String fname) to detect what mime type I need to use in my headers to return different documents.

It was working fine until I tested with fname = "test.csv";. I can make it work with test.jpg or test.pdf but not with test.csv.

String fname = "test.csv";

String mimeType = URLConnection.guessContentTypeFromName(fname);

System.out.println(mimeType);

I have no issue getting the good mimetype for pdf and jpg extension but receive null with the csv one.

I can't seem to find any reason on google as to why it doesn't work. Is it normal behavior or am I missing something from the documentation ?

As a side note, I know of other ways to get the mime type from the filename but was wondering about this.

1 Answers
Related