You can't do it yourself easily, though there are tricks. If you know that it's either Unicode
OR a JPEG, you can look for the JPEG header, and rule JPEG out if the header isn't found. Or if you're limiting the text to standard ASCII, you can probably be pretty certain it's text if each byte's value is 127 or less. But that gets blown away if your text is 8-bit MIME or Unicode, or if you're looking at a UUEncoded file, which is a non-text entity encoded into 7-bit text-only characters for the purpose of easy SMTP transportability. A zipped or tarred file might look like binary data on the surface, but could contain a text file within. A UUEncoded file will look like text on the outside but may contain binary data within. Just like a JPEG looks like binary data on the outside and yet represents an image within.
The problem is that the more varients of "plain old text" you consider to be plain old text, the more difficult it becomes to distinguish it from non-text.
That being the case, you can guess based on various criteria.
Dave
"If I had my life to live over again, I'd be a plumber." -- Albert Einstein