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

(TCO 13) Include the _____ namespace in your C# program to enable it to modify e

ID: 641510 • Letter: #

Question

(TCO 13) Include the _____ namespace in your C# program to enable it to modify existing files. (Points : 3)
System.File.IO
System.Collections.Generic
System.File
System.IO


Question 2.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


Question 3.3. (TCO 13) To make your C# program put a new file called "newFile.txt" in the current directory, write _____. (Points : 3)
File.Create("newFile.txt");
File.CreateNew("newFile.txt");
File myFile = new File("newFile.txt");
File myFile = new FileStream("newFile.txt");


Question 4.4. (TCO 13) To print out the date a file called "plans.txt" was created, write _____. (Points : 3)
Console.WriteLine(File.FileInfo("plans.txt");
Console.WriteLine(GetFileInfo("plans.txt");
Console.WriteLine(GetCreationTime("plans.txt");
Console.WriteLine(File.GetCreationTime("plans.txt"));


Question 5.5. (TCO 13) The following C# statement will _____.

Console.WriteLine(Directory.Exists(Directory.GetCurrentDirectory()));
(Points : 3)
print out "true"
print out "true" if there are files in the current directory
print out "true" if there the current directory has subdirectories
throw an exception


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

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


Question 7.7. (TCO 13) Although the _____ class is useful for working with byte-level data, the _____ class facilitates working with data in readable (text) format. (Points : 3)
IO.Stream, IO.StreamReader
IO.StreamReader, IOStream
System.IO, IO.StreamReader
IO.StreamReader, System.IO


Question 8.8. (TCO 13) To avoid potential runtime errors that may occur when working with directories, always _____. (Points : 3)
enclose file access statements inside try

Explanation / Answer

1)System.File.IO

2)call File.Exists() to make sure the file exists

3)File.Create("newFile.txt");

4)Console.WriteLine(File.GetCreationTime("plans.txt"));

5)print out "true"

6)all file names in current directory

7)IO.Stream, IO.StreamReader

8)all of the above

9)opening file to write and giving permission to write in to that file

10)ReadBytes(), StreamReader

11)
class WriteTextFile
{
static void Main()
{

string[] lines = { "First name", "last name"};
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:UsersPublicTestFolderWriteLines2.txt"))
{
foreach (string line in lines)
{
file.WriteLine(line);
}
}
}