How to fetch the MIME type from byte array in Java 6?
You can use the MimetypesFileTypeMap
provided class from Java 6. This class is exclusively used to fetch the MIME type.
Use it to fetch the MIME type as shown below:
byte[] content = ;
InputStream is = new BufferedInputStream(new ByteArrayInputStream(content));
String mimeType = URLConnection.guessContentTypeFromStream(is);
For fetching from File you can use below code:
MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
String mime = mimeTypesMap.getContentType(file);