Writing Files
Recap
- We can use the
StreamWriterobject for writing files; - If the file at the specified path does not exist, the
StreamWriterobject creates it; - If the file at the specified object already exists, the
StreamWriterobject by default overwrites it - which means that the previous content will be deleted. We will learn how to prevent that in the upcoming section; StreamWriterhas aWriteLinemethod 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 aWritemethod, 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 theStreamWriterobject either by using theClose()method or by utilizing theusingstatement to automatically close it after use.
Everything was clear?
Thanks for your feedback!
SectionΒ 1. ChapterΒ 8
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 2.22
Writing Files
Swipe to show menu
Recap
- We can use the
StreamWriterobject for writing files; - If the file at the specified path does not exist, the
StreamWriterobject creates it; - If the file at the specified object already exists, the
StreamWriterobject by default overwrites it - which means that the previous content will be deleted. We will learn how to prevent that in the upcoming section; StreamWriterhas aWriteLinemethod 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 aWritemethod, 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 theStreamWriterobject either by using theClose()method or by utilizing theusingstatement to automatically close it after use.
Everything was clear?
Thanks for your feedback!
SectionΒ 1. ChapterΒ 8