Quiz
To see whether you took a big enough byte from the tree of knowledge during this hour, answer the following questions about input and output streams in Java.
Questions
1: | Which of the following techniques can be used to convert an array of bytes into a string?
Call the array's toString() method. Convert each byte to a character, and then assign each one to an element in a String array. Call the String() constructor method with the array as an argument.
| 2: | What kind of stream is used to read from a file in a Java program?
| 3: | What method of the File class can be used to determine the size of a file?
|
AnswersA1:
| c. You can deal with each byte individually, as suggested in answer b., but you can easily create strings from other data types. | A2:
| a. An input stream is created from a File object or by providing a filename to the input stream's constructor method. | A3:
| c. This method returns a long representing the number of bytes in the stream. |
|