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?