Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Differences between FileInputStream FileReader

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw these two examples in the following tutorial - http://download.oracle.com/javase/tutorial/essential/io/charstreams.html

FileReader/FileWriter


FileInputStream/FileOutputStream


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

Thanks
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it because java stores characters in 16bit UNICODE or is there any other specific reason?
 
Mark Guo
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FileInputStream to read the image data , such as raw byte stream.
Character stream to read, consider using FileReader.
 
Stephan van Hulst
Bartender
Pie
Posts: 5566
53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.coderanch.com/t/511292/java/java/Byte-vs-Character-streams
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect thanks!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic