aspose file tools*
The moose likes Beginning Java and the fly likes DataInputStream Help needed while creating file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "DataInputStream Help needed while creating file" Watch "DataInputStream Help needed while creating file" New topic
Author

DataInputStream Help needed while creating file

naveen shrimal
Greenhorn

Joined: Dec 18, 2010
Posts: 14
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...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14108
    
  16

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
naveen shrimal
Greenhorn

Joined: Dec 18, 2010
Posts: 14
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DataInputStream Help needed while creating file