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

Зміст курсу

Introduction to .NET with C#

Writing FilesWriting 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?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 1. Розділ 8
course content

Зміст курсу

Introduction to .NET with C#

Writing FilesWriting 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?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 1. Розділ 8
some-alt