Assuming that the data, txt file exists and has the following content:
Text1
Text2
Text3
Given the code fragment:

What is the result?
A.
text1-
text2-
text3-
text3
B.
text1-text2-text3
text1
text2
text3
C.
text1-text2-text3
A java.lang.indexoutofBoundsException is thrown.
The answer is D because the code fragment reads the file ''data.txt'' and collects all the lines in the file into a single string, separated by hyphens. Then, it prints the resulting string. Next, it attempts to read the fourth line in the file (index 3) and print it. However, since the file only has three lines, an IndexOutOfBoundsException is thrown.Reference:
Oracle Certified Professional: Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Read contents of a file using Files class in Java
Antonio
4 months agoAshanti
4 months agoPhung
4 months agoEden
5 months agoBeula
5 months agoHerman
5 months agoBrett
5 months agoBasilia
5 months agoEleonora
6 months agoLeatha
6 months agoLavonda
6 months agoTennie
6 months agoLuann
6 months agoBrittani
6 months agoMarti
6 months agoJoanna
6 months ago