This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
When I am creating file using DataInputStream and entering primitive data types in the file named "a.txt" it shows some encoded text but when i read the same file through it displays output as expected ....
Here is the code...
DataOutputStream writes the values of variables and objects in a binary format, that you cannot read with a text editor or display in a console window as text. Don't save this data in a *.txt file, because it isn't text.
Ofcourse, if your program reads the file with a DataInputStream, it will be able to interpret the binary data in the file and display it correctly (the DataInputStream doesn't care that the file extension is "txt", even though it does not contain plain text).
Java has two kinds of I/O classes: InputStreams and OutputStreams, and Readers and Writers. The first are for reading and writing binary data. The second are for reading and writing text.
If you want to write data as text, use a Writer. For example a FileWriter.