Link to home
Start Free TrialLog in
Avatar of cofactor
cofactor

asked on

DataInputStream/DataOutputStream

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 !!)

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cofactor
cofactor

ASKER

>...No it is for writing primitives in binary format

plz explain a little bit.

eg. writeInt(1) does not write the character '1' to the file it writes the binary representation (4 bytes) of the integer 1
>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 ?



> 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