Previous Section  < Day Day Up >  Next Section


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.



Which of the following techniques can be used to convert an array of bytes into a string?

  1. Call the array's toString() method.

  2. Convert each byte to a character, and then assign each one to an element in a String array.

  3. Call the String() constructor method with the array as an argument.


What kind of stream is used to read from a file in a Java program?

  1. An input stream

  2. An output stream

  3. Either


What method of the File class can be used to determine the size of a file?

  1. getSize()

  2. read()

  3. length()



c. You can deal with each byte individually, as suggested in answer b., but you can easily create strings from other data types.


a. An input stream is created from a File object or by providing a filename to the input stream's constructor method.


c. This method returns a long representing the number of bytes in the stream.

    Previous Section  < Day Day Up >  Next Section