You are on page 1of 4

Questions On Files And Streams

1. Which of these can act both as an input stream and as an output


stream, based on
the classes provided by the java.io package?
Select all valid answers.
(a) !le
(b) network connection
(c) pipe
(d) string
(e) n array of chars
2. Which of these statements about the constant named separator of the
"ile class are
true?
Select all valid answers.
(a) #he variable is of type char.
(b) #he variable is of type String.
(c) $t can be assumed that the value of the variable always is the
character %&%.
(d) $t can be assumed that the value of the variable always is one of %&%,
%'% or %(%.
(e) #he separator can consist of more than one character.
3. Which one of these methods in the "ile class will return the name of
the entry,
e)cluding the speci!cation of the directory in which it resides?
Select the one right answer.
(a) getbsolute*ath()
(b) get+ame()
(c) get*arent()
(d) get*ath()
(e) +one of the above.
4. What will the method length() in the class "ile return?
Select the one right answer.
(a) #he number of characters in the !le.
(b) #he number of kilobytes in the !le.
(c) #he number of lines in the !le.
(d) #he number of words in the !le.
(e) +one of the above.
5. !le is readable but not writable on the !le system of the host. What
will be the
result of calling the method canWrite() on a "ile object representing this !le?
Select the one right answer.
(a) Security,)ception is thrown.
(b) #he boolean value false is returned.
(c) #he boolean value true is returned.
(d) #he !le is modi!ed from being unwritable to being writable.
(e) +one of the above.
6. What is the type of the parameter given to the method rename#o() in
the class "ile?
Select the one right answer.
(a) "ile
(b) "ile-escriptor
(c) "ile+ame"ilter
(d) String
(e) char./
7. $f write(0)01234567) is called on an instance of 8utputStream, what
will be written to
the destination of the stream?
Select the one right answer.
(a) #he bytes 0)01, 0)23, 0)34, 0)45 and 0)67, in that order.
(b) #he bytes 0)67, 0)45, 0)34, 0)23 and 0)01, in that order.
(c) #he byte 0)01.
(d) #he byte 0)67.
(e) +one of the above.
8. 9iven the following code, under which circumstances will the method
return
false?
public static boolean test(nputStream is! t"ro#s O$%ception &
int 'alue ( is.read(!)
return 'alue (( ('alue * +%,!)
-
Select all valid answers.
(a) character of more than : bits was read from the stream.
(b) n $&8 error occurred.
(c) +ever.
(d) #he end of the input was reached in the input stream.
.. Which of these classes provides methods for writing binary
representations of
primitive ;ava types?
Select all valid answers.
(a) -ata8utputStream
(b) "ile8utputStream
(c) 8bject8utputStream
(d) *rintStream
(e) <u=ered8utputStream
1+. Which of these are valid parameter types for the write()
methods of the Writer
class?
Select all valid answers.
(a) #ype String
(b) #ype char
(c) #ype char./
(d) #ype int
11. What is the default encoding for an 8utputStreamWriter?
Select the one right answer.
(a) ::5>?1
(b) @#":
(c) @nicode
(d) #he default is systemAdependent.
(e) #he default is not systemAdependent, but is none of the above.
12. Which of these integer types do not have their own print()
method in the
*rintWriter class?
Select all valid answers.
(a) byte
(b) char
(c) int
(d) long
(e) ll have their own print() method.
13. Bow can one access the standard error stream?
Select all valid answers.
(a) $t is accessed as a member of the class System.err.
(b) $t is accessed as a static variable named out in the class System.
(c) $t is accessed as a static variable named err in the class System.
(d) $t is accessed as a static variable named err in the class Cuntime.
(e) $t is returned by a method in the class System.
14. Which of the these are valid access mode speci!ers for a
constructor of the
Candomccess"ile class?
Select all valid answers.
(a) DD
(b) DrD
(c) DrwD
(d) DwD
(e) DwrD
(f) null
15. Which of the following method calls would, if e)ecuted on a
Candomccess"ile
object, position the !le pointer so that reading the last byte of the !le could
be done
with a single call to read()?
Select the one right answer.
(a) seek(length())
(b) seek(length()E1)
(c) seek(length()E2)
(d) seek(length()A1)
(e) seek(length()A2)
16. Bow many methods are de!ned in the SerialiFable interface?
Select the one right answer.
(a) +one
(b) 8ne
(c) #wo
(d) #hree
(e) +one of the above.
17. Which of the following best describes the data an
8bject8utputStream can write?
Select the one right answer.
(a) <ytes and other primitive ;ava types.
(b) 8bject hierarchies.
(c) 8bject hierarchies and primitive ;ava types.
(d) Single objects.
(e) Single objects and primite ;ava types.

You might also like