Does any one know how to read the header of a file in java using “magic numbers” or ascii values to get the name of the extension of a file
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Maybe not the answer you wanted, but as you gave us very little information …
In unixoid systems (Linux, Mac, *BSD) you have the file command, that
E.g.
Using Runtime.exec(…) you could invoke that program and parse its output.
Edit 1:
To determine if a given file is a PNG:
Edit 2:
Sometimes URLConnection.getContentType() works, too, for local files:
But your comments sound like you have to implement the method by yourself, not using external programs (?).