What is the result if the report.txt file contains Welcome to the world of Java?

Given the code fragment:
<code>
public static void main(String[] args) {
Path file = Paths.get(“D:\\company\\report.txt”);
try (SeekableByteChannel sbc = Files.newByteChannel(file,new OpenOption[]
</code>
What is the result if the report.txt file contains Welcome to the world of Java?

Given the code fragment:
<code>
public static void main(String[] args) {
Path file = Paths.get(“D:\\company\\report.txt”);
try (SeekableByteChannel sbc = Files.newByteChannel(file,new OpenOption[]
</code>
What is the result if the report.txt file contains Welcome to the world of Java?

A.
The file contains the first five characters.

B.
The file contains the first four characters.

C.
The contents of the file remain unchanged.

D.
A NonWritableChannelException is thrown at runtime.

Explanation:
The truncate line will not change the file since the file size is less than 30.
Reference: Interface SeekableByteChannel



Leave a Reply 0

Your email address will not be published. Required fields are marked *