Difference Between Binary and Text Files

Scotty Moe

Updated on:

Difference Between Binary and Text Files

To understand the difference between binary and text files we first should look at some other concepts as given below.

How Java views files:

In Java the files are viewed as sequential streams of bytes. Stream itself is sequence of data.when building program in Java we often need to interact with out side world, i.e files,network streams etc, Or when we want to store the state of the object we need to interact with these out side world .But since this tutorial is intended for the files so we keep focus on files.

Note:
Operating systems are responsible to indicate the java programs when the end of file is reached.

There are two types of files that we will use.

  1. Byte-Based
  2. character Based.

Byte-Based Files.

  1. These files are also called binary files. Because when the data is taken as input or shown as output is in format of binary.
  2. For example, if we store the value 6, it would be stored in the binary format of 110=6. And this value can be used as integer for calculation purpose.
  3. Can not be understood by humans .
  4. The binary files are read by the Java programs .
  5. We use InputStream and OutPutStream classes when dealing with bytebased data.

Character-Based files:

  1. These files are also called text files. Because when the data is taken as input or shown as output, is in format of sequence of character.
  2. For example if we use to store the value 5 as character-based stream, it will be stored as binary format of character 000000000, 00110101=(binary of )53=(Unicode of)5. The numeric values such as 5,6,9 are treated as character as we can say that “trustingeeks.com is 5 months old”.
  3. The data in the file can be easily understood by humans.
  4.  The character based files are read by text-editor. 
  5. Writer and Reader classes are used when dealing with character based data.                                                                                                                          Learn how to write data to text files                                                                                                                                                                                         Learn how to read data from text files

1 thought on “Difference Between Binary and Text Files”

Leave a Comment