Вы находитесь на странице: 1из 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) A file
(b) A network connection
(c) A pipe
(d) A string
(e) An array of chars
2. Which of these statements about the constant named separator of the File 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 File class will return the name of the entry,
e"cluding the specification of the directory in which it resides?
Select the one right answer.
(a) getAbsolutePath()
(b) getName()
(c) getParent()
(d) getPath()
(e) #one of the above.
4. What will the method length() in the class File return?
Select the one right answer.
(a) he number of characters in the file.
(b) he number of kilobytes in the file.
(c) he number of lines in the file.
(d) he number of words in the file.
(e) #one of the above.
5. A file is readable but not writable on the file system of the host. What will be the
result of calling the method canrite() on a File ob$ect representing this file?
Select the one right answer.
(a) A Securit!"#ception is thrown.
(b) he boolean value $alse is returned.
(c) he boolean value true is returned.
(d) he file is modified 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
File?
Select the one right answer.
(a) File
(b) File&escriptor
(c) FileNameFilter
(d) String
(e) char'(
7. !f )rite(*#*+,-./01) is called on an instance of 2utputStream, what will be
written to
the destination of the stream?
Select the one right answer.
(a) he bytes *#*+, *#,-, *#-., *#./ and *#01, in that order.
(b) he bytes *#01, *#./, *#-., *#,- and *#*+, in that order.
(c) he byte *#*+.
(d) he byte *#01.
(e) #one of the above.
8. %iven the following code, under which circumstances will the method return
$alse?
public static boolean test(InputStream is) throws IOException {
int value = is.read();
return value == (value & x!!);
"
Select all valid answers.
(a) A character of more than & bits was read from the stream.
(b) An !'( error occurred.
(c) #ever.
(d) he end of the input was reached in the input stream.
9. Which of these classes provides methods for writing binary representations of
primitive )ava types?
Select all valid answers.
(a) &ata2utputStream
(b) File2utputStream
(c) 2bject2utputStream
(d) PrintStream
(e) 3u$$ere42utputStream
10. Which of these are valid parameter types for the )rite() methods of the riter
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 2utputStreamriter?
Select the one right answer.
(a) &&*+,-
(b) ./&
(c) .nicode
(d) he default is system0dependent.
(e) he default is not system0dependent, but is none of the above.
12. Which of these integer types do not have their own print() method in the
Printriter class?
Select all valid answers.
(a) b!te
(b) char
(c) int
(d) long
(e) All have their own print() method.
13. 1ow can one access the standard error stream?
Select all valid answers.
(a) !t is accessed as a member of the class S!stem.err.
(b) !t is accessed as a static variable named out in the class S!stem.
(c) !t is accessed as a static variable named err in the class S!stem.
(d) !t is accessed as a static variable named err in the class 5untime.
(e) !t is returned by a method in the class S!stem.
14. Which of the these are valid access mode specifiers for a constructor of the
5an4omAccessFile class?
Select all valid answers.
(a) 66
(b) 6r6
(c) 6r)6
(d) 6)6
(e) 6)r6
(f) null
15. Which of the following method calls would, if e"ecuted on a 5an4omAccessFile
ob$ect, position the file pointer so that reading the last byte of the file could be done
with a single call to rea4()?
Select the one right answer.
(a) see7(length())
(b) see7(length()8+)
(c) see7(length()8,)
(d) see7(length()9+)
(e) see7(length()9,)
16. 1ow many methods are defined in the Seriali:able interface?
Select the one right answer.
(a) #one
(b) (ne
(c) wo
(d) hree
(e) #one of the above.
17. Which of the following best describes the data an 2bject2utputStream can write?
Select the one right answer.
(a) 2ytes and other primitive )ava types.
(b) (b$ect hierarchies.
(c) (b$ect hierarchies and primitive )ava types.
(d) Single ob$ects.
(e) Single ob$ects and primite )ava types.