This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Differences between FileInputStream FileReader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Differences between FileInputStream FileReader" Watch "Differences between FileInputStream FileReader" New topic

Differences between FileInputStream FileReader

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

I saw these two examples in the following tutorial -



One of the difference listed in the above is that both CopyBytes and CopyCharacters use an int variable to read to and write from. However, in CopyCharacters, the int variable holds a character value in its last 16 bits; in CopyBytes, the int variable holds a byte value in its last 8 bits. Can someone explain this difference please (i.e why 16bit on one and not the other. )

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Is it because java stores characters in 16bit UNICODE or is there any other specific reason?
Mark Guo
Ranch Hand

Joined: Nov 17, 2010
Posts: 58
FileInputStream to read the image data , such as raw byte stream.
Character stream to read, consider using FileReader.
Stephan van Hulst

Joined: Sep 20, 2010
Posts: 3983

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Perfect thanks!
Have you checked out Aspose?
subject: Differences between FileInputStream FileReader
It's not a secret anymore!