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.
- Byte-Based
- character Based.
Byte-Based Files.
- These files are also called binary files. Because when the data is taken as input or shown as output is in format of binary.
- 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.
- Can not be understood by humans .
- The binary files are read by the Java programs .
- We use InputStream and OutPutStream classes when dealing with bytebased data.
Character-Based files:
- 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.
- 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”.
- The data in the file can be easily understood by humans.
- The character based files are read by text-editor.
- 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
Good job Bro.