Sams Teach Yourself Java™ in 24 Hours (Covering Java 7 and Android)

(singke) #1
ptg7068951

Workshop 297


  1. What kind of stream is used to read from a file in a Java program?
    A. An input stream
    B. An output stream
    C. Either

  2. What method of the Fileclass can be used to determine the size of a
    file?
    A. getSize()
    B. read()
    C. length()


Answers



  1. C.Yo u c a n d e a l w i t h e a c h by t e i n d i v i d u a l l y,as suggested in answer B,
    but you can easily create strings from other data types.

  2. A.An input stream is created from a Fileobject or by providing a file-
    name to the input stream’s constructor method.

  3. C.This method returns a long, representing the number of bytes in the
    stream.


Activities


Toexperience the refreshing feeling of wading through another stream,test
the waters with the following activities:


. Write an application that reads the ID3 tags of all MP3 files in a folder
and renames the files using the artist,song,and album information
(when it is provided).
. Write a program that reads a Java source file and writes it back without
any changes under a new name.
. Buy a copy of the song “Come on and Gettit” by Marian Black.


To s e e J av a p r o g r a m s t h a t i m p l e m e n t t h e s e a c t i v i t i e s ,visit the book’s website
at http://www.java24hours.com.

Free download pdf