0% found this document useful (0 votes)
53 views2 pages

File Handling in C#

File handling in C# involves operations such as creating, reading, writing, and appending files, utilizing streams for communication. The System.IO namespace provides classes like StreamWriter and StreamReader for writing and reading data, respectively, with methods such as Close(), Flush(), Write(), and ReadLine(). These classes facilitate efficient data manipulation in a structured format.

Uploaded by

akshaya262021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views2 pages

File Handling in C#

File handling in C# involves operations such as creating, reading, writing, and appending files, utilizing streams for communication. The System.IO namespace provides classes like StreamWriter and StreamReader for writing and reading data, respectively, with methods such as Close(), Flush(), Write(), and ReadLine(). These classes facilitate efficient data manipulation in a structured format.

Uploaded by

akshaya262021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Basics of File Handling in C#

Generally, the file is used to store the data. The term File Handling refers to the
various operations like creating the file, reading from the file, writing to the file,
appending the file, etc. There are two basic operation which is mostly used in
file handling is reading and writing of the file. The file becomes stream when we
open the file for writing and reading. A stream is a sequence of bytes which is
used for communication. Two stream can be formed from file one is input
stream which is used to read the file and another is output stream is used to
write in the file. In C#, System.IO namespace contains classes which handle
input and output streams.

StreamWriter Class
The StreamWriter class implements TextWriter for writing
character to stream in a particular format. The class contains the
following method which are mostly used.

Method Description

Closes the current StreamWriter object and stream associate with


Close() it.

Clears all the data from the buffer and write it in the stream
Flush() associate with it.

Write data to the stream. It has different overloads for different data
Write() types to write in stream.
Method Description

It is same as Write() but it adds the newline character at the end of


WriteLine() the data.

StreamReader Class
The StreamReader class implements TextReader for reading
character from the stream in a particular format. The class
contains the following method which are mostly used.

Method Description

Closes the current StreamReader object and stream associate with


Close() it.

Reads the next character in input stream and increment characters


Read() position by one in the stream

Reads a line from the input stream and return the data in form of
ReadLine() string

You might also like