Exam 1z0-829 All QuestionsBrowse all questions from this exam
Question 17

Given the content of the in.txt file:

0123456789

and the code fragment:

What is the content of the out.txt file?

    Correct Answer: F

    The code reads from the 'in.txt' file and writes to the 'out.txt' file using a buffer of size 8 characters. The content of 'in.txt' is '0123456789', which has 10 characters. In the first iteration, the buffer will read '01234567' and write it to 'out.txt'. In the second iteration, the buffer will read the remaining '89' and the leftover characters from the previous buffer, which results in '89234567' due to the buffer's fixed size. Consequently, the final content of 'out.txt' becomes '0123456789234567'.

Discussion
j_jainOption: F

Correct answer is F Buffer already contains 01234567 and we have 89 left so next time it will replace 0 with 8 and 1 with 9. As there is no data left so it will write 89234567.

james2033Option: F

package q17; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class Q17 { public static void main(String[] args) throws Exception { char[] buffer = new char[8]; int count = 0; try (FileReader in = new FileReader("D:\\in.txt"); FileWriter out = new FileWriter("D:\\out.txt")) { while ((count = in.read(buffer)) != -1) { out.write(buffer); } } // catch (FileNotFoundException e) { // throw new RuntimeException(e); // } catch (IOException e) { // throw new RuntimeException(e); // } } } // Result: // 0123456789234567

omegavalouOption: F

why is the right option F?

4d8d7fe

In the first iteration de char array is 01234567(only can contain 8 size). But in the second iteration is 89234567

xplorerpjOption: F

Correct answer is F

xplorerpjOption: C

Buffer only contains [0, 1, 2, 3, 4, 5, 6, 7] In second iteration, in.read(buffer) becomes "-1" . How is the answer F "0123456789234567" ? I ran the program & see only 01234567 in output file.

supersquaxOption: F

Correct option is F, because the buffer is of size 8. Therefore, it can only read 8 characters at a time. First 8 digits in F are correct and the entire thing is of length 16. Although the first 8 digits in B and E are correct, the entire length doesn't add it. Doesn't make sense that the buffer first reads 8 chars, then 6 more in B or 7 more in E.

meltedoliveOption: F

right option is F

TojoseOption: F

the right option is F. 0123456789234567