0

Im hoping to find a way to identify the file type through some java library instead of extracting the file name/path and getting the extension.

Thanks!

  • I have a question on if someone uploads a pdf file but actually changes the extension to .doc and tries to upload it. Thus i would need to know how to catch this exception. – Jensen Lim Apr 24 '17 at 11:58
  • A PDF starts with 25 50 44 46 (hex signature), you can read the first bytes to guess the file types. This is typically what I did when I implemented the image file format detection within JOGL: http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/texture/ImageType.Util.html#getFileSuffix(byte[]) – gouessej Apr 24 '17 at 12:04
  • Thanks @gouessej i guess i can read the bytes to help determine the file type – Jensen Lim Apr 25 '17 at 01:53

0 Answers0