Java OCA OCP Practice Question 3079

Question

Given this code segment:

BufferedReader br = new BufferedReader(new FileReader("names.txt"));
System.out.println(br.readLine());
br.mark(100);   // MARK
System.out.println(br.readLine());
br.reset();     // RESET
System.out.println(br.readLine());

Assume that names.txt exists in the current directory, and opening the file succeeds, and br points to a valid object.

The content of the names.txt is the following:.

olivea
emma
margaret
emily

Choose the correct option.

a)   this code segment prints the following:

     olivea// ww  w. j  a  va2s  .  co m
     emma
     margaret

b)   this code segment prints the following:

     olivea
     emma
     olivea

c)   this code segment prints the following:

     olivea
     emma
     emma

d)   this code segment throws an IllegalArgumentException in the line MARK

e)   this code segment throws a CannotResetToMarkPositionException in the
     line RESET


c)

Note

the method void mark(int limit) in BufferedReader marks the current position for resetting the stream to the marked position.

the argument limit specifies the number of characters that may be read while still preserving the mark.

this code segment marks the position after olivea is read, so after reading "emma," when the marker is reset and the line is read again, it reads "emma" once again.




PreviousNext

Related