How do I know that a particular file is in binary or text format without relying on the extention of a file?

John Zukowski

Basically, you guess by reading the first few bytes of the file. Most binary file formats have a hardcoded constant there, called a magic number. As long as you have a complete list of magic numbers for the possible binary file formats you might come across, you can try your best to determine if something is binary / text. For instance, all Java class files start with 0xCAFEBABE.