Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

DataInputStream/DataOutputStream

Posted on 2005-05-04
5
Medium Priority
?
283 Views
Last Modified: 2010-03-31
i dont understand the use of DataInputStream/DataoutputStream. It is called , these classes are  usued for primitive types(int, char etc).

means what ? suppose i have a file which contains like below..



12 A B C 1245


so these are primitive data, because these are ints, chars READABLE things, right ? so i CAN use datainputstream to read these data ? but same thing i could do it using a FIleReader!!....is not it ?  

so , dont u think DataInputStream/DataoutputStream is a redundant class ? (bocz FileReader/ FileWriter  can do theirs job !!)

0
Comment
Question by:cofactor
  • 3
  • 2
5 Comments
 
LVL 92

Accepted Solution

by:
objects earned 140 total points
ID: 13924760
No it is for writing primitives in binary format, not as text.
For reading/writing text you would use a Reader and Writer.
0
 

Author Comment

by:cofactor
ID: 13924789
>...No it is for writing primitives in binary format

plz explain a little bit.

0
 
LVL 92

Expert Comment

by:objects
ID: 13924809
eg. writeInt(1) does not write the character '1' to the file it writes the binary representation (4 bytes) of the integer 1
0
 

Author Comment

by:cofactor
ID: 13924841
>eg. writeInt(1) does not write the character '1' to the file >it writes the binary representation (4 bytes) of the >integer 1

ohh. that means, it is taking a primitive param (here integer 1 ) but outputing a binary result.


what  will happen when it will use  readInt() ?




Filereader,Filewriter does txt--->txt conversion , so here is the difference !  right ?



0
 
LVL 92

Expert Comment

by:objects
ID: 13924971
> what  will happen when it will use  readInt() ?

It will read the next 4 bytes and interpret them as an integer


> Filereader,Filewriter does txt--->txt conversion , so here is the difference !  right ?

sort of, you actually write chars to a writer

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question