1z0-829 Exam QuestionsBrowse all questions from this exam

1z0-829 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?

Show Answer
Correct Answer: BF

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

8 comments
Sign in to comment
omegavalouOption: F
Jan 22, 2024

why is the right option F?

4d8d7fe
Jul 11, 2024

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

james2033Option: F
Feb 17, 2024

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

j_jainOption: F
Mar 1, 2024

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.

TojoseOption: F
Jan 12, 2024

the right option is F. 0123456789234567

meltedoliveOption: F
Jan 16, 2024

right option is F

supersquaxOption: F
Jan 31, 2024

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.

xplorerpjOption: C
Jun 17, 2024

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.

xplorerpjOption: F
Jun 24, 2024

Correct answer is F