How to recognize if given content (file, String or InputStream) is in Java Properties file format?
The content is stored in database and should be parsed into Properties if it is a properties file. However, with a simple test I’ve noticed, that java.util.Properties parsed without error an xml file </log4j). It could ‘parse’ also a normal text file.
So, if the java.util.Properties can parse practically everything what is text, how can I recognize if I have properties file or not? Need I check if this is in any other recognized format, can I use some heuristics or there is an existing library with such functionality?
I would do it this way
This is just a prototype, regex may need improvement, see Properties.load API. I would ignore xml version, but if need be it’s even simpler since there is DTD in API