4 stars based on
Lets take an example and try to understand in terms of byte and its interpretation whats happening. What it wants to say is save the data in a way based on the type. Understanding the difference between Binary and text files using Java. By BytePadding on Apr 07, in Java. Understanding the difference between Binary and Text Files Lets start with the basic ideas.
A file is saved on Hard-disk. A hard-disk only has two stated magnetized demagnetized which represent the two states of binary. Any file saved on binary to 1 of 8 editor utf has to follow the semantics of the two states. Secondary storage just stores an array of bits.
How to encode or decode the 8 bits byte is not known to hard-disk. Letter words and symbols are unknown to the secondary storage. Key Take Aways All files are binary in nature. Text file is a special case of binary file, where we encode the data in a way that it is human readable when read through a text editor A text file saved on secondary storage is store in binary form. Text files is like a protocol that one follows so that the writer writes in a specific way encodethe text reader process decodes it in a way, that its become human readable.
Lets take a String: What it means is Save it in a way that when the text editor reads itit should be able to display The bits sequence saved on disk will be: Hence text format like any other protocol where in the reader and write have predefined way of reading and writing data so that the final outcome is human readable, as the lookup is being done from UTF-8 sequence.
If one needs to save 0 irrespective of it is a char or int in a text file It will need one Byte to save it. Every thing is treated as a symbol in text file, from the symbol based on the sequence it is mapped to binary to 1 of 8 editor utf UTF-8 encoding the bits sequence is saved.
Integer 12 will be treated as String While reading the binary file, the schema which was used to write the data, needs to be present as there is no information present on how to decode the bytes. Do remember if you binary to 1 of 8 editor utf two bytes then can be decoded as char or short in Java. The interpretation is based on the schema with which you have written. Int 1 in Binary will be saved as If the binary of int 1 is binary to 1 of 8 editor utf by a text editor it will be displayed as