I would like to determine real file extension for security reason.
How can I do that?
Search the FILExt database to find out how to open the unknown file. Searching online is always the best method to learn about a new file type, and the best place to do it is the Filext database. It is an impressive database which contains over 50,000 known file extensions.
A file extension is just the portion of the file name after the last period. The file extension is . txt which typically indicates that the file contains text data. To create your own file extension all you need to do is to place the desired extension after the last period in the filename.
Here is how you can use it so Windows will display file extensions: Press Win + R to open a Run dialog. Type cmd and click OK. In the Command Prompt window copy the next command reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v HideFileExt /t REG_DWORD /d 0 /f.
Supposing you really mean to get the true content type of a file (ie it's MIME type) you should refer to this excellent answer.
You can get the true content type of a file in Java using the following code:
File file = new File("filename.asgdsag");
InputStream is = new BufferedInputStream(new FileInputStream(file));
String mimeType = URLConnection.guessContentTypeFromStream(is);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With