How can I know at run time if the file in a specified folder is text rendering or not? (i.e files like csv, html, etc that can be displayed as text)
I do not want to do this via extension matching (by checking for .txt, .html extensions etc).
Suppose if there is a jpg file, I deliberately rename the extension to .txt and still the java code should be able to detect that this file (although with .txt extn) cannot be rendered as text.
How can I achieve this in java?
You could guess the type by scanning the file and usinng Character.html#isISOControl to check whether there are non printable character included.
Binary files usually include headers which often contain control chars see this list of File Signatures most of them would be detected by isISOControl.