ptg7068951
296 HOUR 20: Reading and Writing Files
Q&A
Q. Why do some of the byte stream methods in this hour use integers as
arguments? Should they be using bytearguments?
A. There’s a difference between the bytes in a stream and the bytes repre-
sented by the byteclass. A bytein Java has a value ranging from –128
to 127,while a byte in a stream has a value from 0 to 255. You often
have to use intwhen working with bytes for this reason—it can hold
the values 128 to 255,whereas bytecannot.
Q. What is Mumblety-Peg?
A. It’s a schoolyard game played by children with pocketknives.
In the simplest form,players stand and throw knives at their own feet.
The one whose knife lands closest wins. Other versions involve throw-
ing the knife at each other so the opponent has to stretch a foot to
where it lands. The player who stretches too far and falls down loses.
The name comes from a rule that the winner could pound a peg into
the ground with three blows of the knife. The loser had to “mumble the
peg,” removing it solely with his teeth.
The game faded from popularity in the early 20th century when the
world reached the collective realization that children throwing knives at
each other might not be the greatest idea in the world.
Workshop
To s e e w h e t h e r y o u t o o k a b i g e n o u g h by t e f r o m t h e t r e e o f k n o w l e d g e d u r i n g
this hour,answer the following questions about streams in Java.
Quiz
- Which of the following techniques can be used to convert an array of
bytes into a string?
A. Call the array’s toString()method.
B. Convert each byte to a character and then assign each one to an
element in a Stringarray.
C. Call the String()constructor method with the array as an
argument.