Which option, containing statement(s), inserted at line 3, creates the file and sets its attributes to hidden and read-only?

Given the code fragment:

1. path file = path.get (args.[0])

2. try {

3. } / / statements here

4. catch (IOException) i ) {

5. }

And a DOS-based file system:

Which option, containing statement(s), inserted at line 3, creates the file and sets its attributes to hidden and read-only?

Given the code fragment:

1. path file = path.get (args.[0])

2. try {

3. } / / statements here

4. catch (IOException) i ) {

5. }

And a DOS-based file system:

Which option, containing statement(s), inserted at line 3, creates the file and sets its attributes to hidden and read-only?

A.
DOSFileAttributes attrs = Files.setAttribute(file,”dos:hidden”,”dos: readonly”) Files.createFile(file, attrs)

B.
Files.craeteFile(file);
Files.setAttribute(file,”dos:hidden”,”dos:readonly”);

C.
Files.createFile(file,”dos:hidden”,”dos:readonly”);

D.
Files.createFile(file);
Files.setAttribute(file,”dos:hidden”, true);
Files.setAttribute(file,”dos:readonly”, true);

Explanation:
You can set a DOS attribute using the setAttribute(Path, String, Object, LinkOption…) method, as follows:

Path file = …;
Files.setAttribute(file, “dos:hidden”, true);

Note:
setAttribute
public static Path setAttribute(Path path,
String attribute,
Object value,
LinkOption… options)
throws IOException
Sets the value of a file attribute.

Reference:Interface DosFileAttribute



Leave a Reply 2

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


Naresh

Naresh

Correct Answer D