• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DataInputStream Help needed while creating file

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
naveen shrimal
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was too thinking about this but I want to make it sure. thanks for making it clear to me.
It is very good site.
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic