Recall & Review
beginner
What is the purpose of the
File.Exists method in C#?The
File.Exists method checks if a file exists at a specified path and returns true if it does, otherwise false.Click to reveal answer
beginner
How does
File.ReadAllText work?It reads all the text from a file at a given path and returns it as a single string.
Click to reveal answer
beginner
What does
File.WriteAllText do?It creates a new file or overwrites an existing file with the specified text content.
Click to reveal answer
beginner
Explain the use of
File.Delete.The
File.Delete method removes a file from the file system at the specified path if it exists.Click to reveal answer
intermediate
What does
File.Copy do and what important parameter does it have?It copies a file from a source path to a destination path. It has an optional parameter to specify whether to overwrite the destination file if it already exists.
Click to reveal answer
Which
File method reads all lines from a file into a string array?✗ Incorrect
File.ReadAllLines reads each line of a file into an array of strings.What does
File.Exists return if the file does not exist?✗ Incorrect
File.Exists returns false if the file is not found.Which method would you use to overwrite a file with new text content?
✗ Incorrect
File.WriteAllText creates or overwrites a file with the given text.What happens if you call
File.Delete on a file that does not exist?✗ Incorrect
File.Delete does nothing if the file is not found; it does not throw an error.Which parameter in
File.Copy controls overwriting the destination file?✗ Incorrect
The
overwrite boolean parameter specifies if the destination file should be overwritten.Describe how you would check if a file exists and then read its entire content using File class static methods.
Think about checking first to avoid errors.
You got /3 concepts.
Explain the difference between File.WriteAllText and File.AppendAllText.
Consider what happens to existing file content.
You got /3 concepts.