How can I find out if a file is a text/ASCII file or binary file using Java?

John Zukowski

There is no easy way to tell since ASCII characters are binary. Depending upon how you read the file determines how you treat the data. For instance, the text "CAFE" if read as an int is the value 1128351301. Since Java also deals with Unicode and not just ASCII, you get to worry about 8-bit vs. 16-bit characters, too.

See also How do I know that a particular file is in binary ...