π Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
π Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
1. Which namespace is commonly used for file handling in C#?
Answer:
Explanation:
The System.IO namespace contains types for handling files and data streams, making it the primary namespace used for file handling in C#.
2. How do you create a text file in C#?
Answer:
Explanation:
The File.CreateText method is used to create a new text file in C#. It returns a StreamWriter.
3. What class is used to read text from a file in C#?
Answer:
Explanation:
StreamReader is a class in the System.IO namespace used for reading text from files.
4. Which method is used to write text to a file in C#?
Answer:
Explanation:
File.WriteAllLines() writes a string array to a file, with each string as a line. For appending or continuous writing, StreamWriter can be used.
5. How do you append text to an existing file in C#?
Answer:
Explanation:
File.AppendAllText method appends text to the end of an existing file.
6. What is the purpose of the FileStream class in C#?
Answer:
Explanation:
FileStream is used for reading from and writing to files as streams of bytes, providing control over byte positions in files.
7. Which method checks for the existence of a file in C#?
Answer:
Explanation:
File.Exists method is used to check if a file exists at a specified path.
8. How do you copy a file in C#?
Answer:
Explanation:
The File.Copy method is used to copy a file to a new location.
9. How do you delete a file in C#?
Answer:
Explanation:
File.Delete method is used to delete a specified file.
10. Which class is used to read and write binary files in C#?
Answer:
Explanation:
BinaryReader and BinaryWriter are used for reading and writing binary data to and from files.
11. How do you move a file in C#?
Answer:
Explanation:
The File.Move method is used to move a file to a new location.
12. What is the use of the Path class in C#?
Answer:
Explanation:
The Path class in the System.IO namespace provides methods for manipulating file and directory paths.
13. What exception is commonly associated with file handling errors in C#?
Answer:
Explanation:
IOException is a general exception that occurs when an I/O error happens during file handling operations.
14. How can you read all lines of a text file into a string array in C#?
Answer:
Explanation:
File.ReadAllLines reads all the lines of the specified file into a string array.
15. Which method is used to read all text from a file in one go in C#?
Answer:
Explanation:
File.ReadAllText reads all text from the file and returns it as a single string.
Comments
Post a Comment
Leave Comment