Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 33

Given that course.txt is accessible and contains:

Course : : Java -

and given the code fragment:

public static void main (String[ ] args) {

int i;

char c;

try (FileInputStream fis = new FileInputStream ("course.txt");

InputStreamReader isr = new InputStreamReader(fis);) {

while (isr.ready()) { //line n1

isr.skip(2);

i = isr.read ();

c = (char) i;

System.out.print(c);

}

} catch (Exception e) {

e.printStackTrace();

}

}

What is the result?

    Correct Answer: A

    The key point of this code is the use of isr.skip(2) which skips the first 2 characters of the file content on each iteration of the while loop. Given that the content of course.txt is 'Course : : Java -', the sequence of operations would be as follows: SKIP 2 characters ('Co'), READ 'u', SKIP 2 ('rs'), READ ' ', SKIP 2 (': '), READ ':', SKIP 2 (' J'), READ 'a', SKIP 2 ('va'), READ 'v'. Consequently, 'u: : va' is printed, with the ':' character read and printed as part of the sequence.

Discussion
adnano1234Option: B

The answer is : ueJa

DestroyerOption: B

The answer is B

M_JawadOption: B

answer is ue ja

asdfjhfgjuaDCVOption: B

B is the answer

r1muka5Option: B

Correct answer is B