Domain.com has asked you to create a file management application to monitor the hosts file.
Domain.com has instructed you to change the hosts file if it has been changed.
You, therefore, need to display the size and whether the hosts file is set to read-only.
What should you do?
A.
Use the following code:
FileInfo hosts = new FileInfo(@”C:Windowssystem32driversetchosts”);
Console.WriteLine (“ReadOnly?” + hosts.IsReadOnly);
Console.WriteLine (“Size?” + hosts.Length);
B.
Use the following code:
File hosts = new File(@”C:Windowssystem32driversetchosts”);
Console.WriteLine (“ReadOnly?” + hosts.IsReadOnly);
Console.WriteLine (“Size?” + hosts.Length);
C.
Use the following code:
File hosts = new File(@”C:Windowssystem32driversetchosts”);
Console.WriteLine (“ReadOnly?” + hosts.GetReadOnly);
Console.WriteLine (“Size?” + hosts.GetLength);
D.
Use the following code:
FileInfo hosts = new FileInfo(@”C:Windowssystem32driversetchosts”);
Console.WriteLine (“ReadOnly?” + hosts.IsReadOnly);
Console.WriteLine (“Size?” + hosts.Size);
Explanation:
This code instantiates a FileInfo object using a file path string and outputs the IsReadOnly and Length properties to the command line. The FileInfo object represents the information about a system file. The FileInfo class contains common properties and methods for reading and setting file metadata and contents.
The ISReadOnly property returns a Boolean value indicating whether the file is set to read- only.
The Length property returns the size of the file in bytes.
Incorrect Answers:
B C: You should not use the code that instantiate a File object because the File class does not contain an ISReadOnly or Length property and is a static class. Also, you should not use the code fragments that specify the Size property because no such property exists.
D: You should not use the code fragments that specify the Size method because no such methods exist.
A