Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Writing Files | Introduction
Introduction to .NET with C#
course content

Course Content

Introduction to .NET with C#

Introduction to .NET with C#

1. Introduction
2. Asynchronous Programming and Introduction to Web Services
3. Introduction to Databases with .NET
4. CRUD Operations with MySQL
5. Optimizing Database Operations

bookWriting Files

Recap

  • We can use the StreamWriter object for writing files;
  • If the file at the specified path does not exist, the StreamWriter object creates it;
  • If the file at the specified object already exists, the StreamWriter object by default overwrites it - which means that the previous content will be deleted. We will learn how to prevent that in the upcoming section;
  • StreamWriter has a WriteLine method for writing a line of text into a file. This method automatically moves the cursor to the next line after writing is done. In other words, it automatically appends a "\n" character after the text we write into the file;
  • Similar to WriteLine, there is a Write method, however, it doesn't move the cursor to the next line after writing text into a file;
  • Just like StreamReader, we also need to close the StreamWriter object either by using the Close() method or by utilizing the using statement to automatically close it after use.
Which object is used for writing text into a file line by line?

Which object is used for writing text into a file line by line?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 8
some-alt