Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. (TCO 13) Include the _____ namespace in your C# program to enable it to acces

ID: 3538031 • Letter: 1

Question


1. (TCO 13) Include the _____ namespace in your C# program to enable it to access files and directories. (Points : 3)       System.IO
      System.Collections.Generic
      System
      System.Text

2. (TCO 13) Before your C# program attempts to append data to a file, it should first _____. (Points : 3)       call File.Append to ensure the file can be written to
      call File.Create() to create the file
      call File.Exists() to make sure the file exists
      call File.Write() to make sure the file can be written to

3. (TCO 13) To make your C# program delete a file called "oldFile.doc" in the current directory, write _____. (Points : 3)       File.Close("oldFile.doc");
      File.Close("oldFile.doc", true);
      File.Delete("oldFile.doc");
      File.Delete("oldFile.doc", true);

4. (TCO 13) To print out the time and date a file called "plans.txt" was last accessed, write _____. (Points : 3)       Console.WriteLine(File.GetAccessInfo("plans.txt");
      Console.WriteLine(File.GetLastAccessTime ("plans.txt"));
      Console.WriteLine(GetLastAccessTime ("plans.txt");
      Console.WriteLine(GetAccessTime("plans.txt");

5. (TCO 13) The following C# statement will print out _____.

          Console.WriteLine(Directory.GetParent(Directory.GetCurrentDirectory()));
(Points : 3)       all of the subdirectories of the current directory
      the root directory of the system
      the parent directory of the current directory
      the name and path of the current directory

6. (TCO 13) The following C# code will print out _____.

                DirectoryInfo dir = new
DirectoryInfo(".");
                foreach (FileInfo
fil in dir.GetFiles("*.*"))
                    Console.WriteLine(fil.Extension);
(Points : 3)       the extensions of all subdirectories of the current directory
      the extensions of all files in the current directory
      the extensions of all files in the root directory
      the extensions of all subdirectories of the root directory


7. (TCO 13) Similar to the _____ class method, the _____ class also offers the method WriteLine(). (Points : 3)       StreamReader, StreamWriter
      StreamWriter, StreamReader
      Console, StreamWriter
      StreamWriter, Console

8. (TCO 13) To avoid potential runtime errors that may occur when working with directories, always _____. (Points : 3)       enclose file access statements inside try%u2026catch blocks
      open a file before writing to it
      close a file after using it
      all of the above

9. (TCO 13) In the following code, the statement "myFile.Close()" _____.

            try
            {
              StreamWriter myFile = new StreamWriter("text.txt",true);
              for (int i = 0; i < 10; i++)
                  myFile.WriteLine("Student[{0}]: ", i);
              myFile.Close();
            }
(Points : 3)       releases any resources associated with "text.txt"
      keeps the StreamWriter object "myFile" open
      writes a final newline to "text.txt"
      writes 10 lines to "text.txt"

10. (TCO 13) You're writing a data decryption program. Because your C# code needs to read data from an encrypted file 4 characters at a time, you decide to use the _____ member of the _____ class. (Points : 3)       ReadChar(), BinaryReader
      ReadChars(), BinaryReader
      ReadChar(), StreamReader
      ReadChars(), StreamReader

11. (TCO 13) Write a C# program to write your first and last names (on two separate lines) to a new file called "name.txt." Use the StreamWriter class and appropriate try%u2026catch blocks. Print out any System.IO.IOExceptions. Remember to close the file after writing to it. (Points : 5)       
      

Explanation / Answer

1.A
2.C
3.D
4.D
5.D
6.A
7.A
8.C
9.D
10.A
11.