I've got bytes array in database.
How to extract file extension (mime/type) from byte array in java?
See Question&Answers more detail:osI've got bytes array in database.
How to extract file extension (mime/type) from byte array in java?
See Question&Answers more detail:osIt turned out that there is a decent method in JDK
's URLConnection
class, please refer to the following answer: Getting A File's Mime Type In Java
If one needs to extract file extension from byte array instead of file, one should simply use java.io.ByteArrayInputStream
(class to read bytes specifically from byte arrays) instead of java.io.FileInputStream
(class to read bytes specifically from files) like in the following example:
byte[] content = ;
InputStream is = new ByteArrayInputStream(content);
String mimeType = URLConnection.guessContentTypeFromStream(is);
//...close stream
Hope this helps...