2. • A file is a collection of data stored in a disk with a
specific name and a directory path. When a file is
opened for reading or writing, it becomes a stream.
• The stream is basically the sequence of bytes passing
through the communication path. There are two main
streams: the input stream and theoutput stream.
The input stream is used for reading data from file
(read operation) and the output stream is used for
writing into the file (write operation).
• C# I/O Classes
• The System.IO namespace has various classes that are
used for performing numerous operations with files,
such as creating and deleting files, reading from or
writing to a file, closing a file etc.
• The following table shows some commonly used non-
abstract classes in the System.IO namespace:
3. • C# FileStream
• C# FileStream class provides a stream for file
operation. It can be used to perform synchronous and
asynchronous read and write operations. By the help of
FileStream class, we can easily read and write data into
file.
• C# FileStream example: writing single byte into file
• Let's see the simple example of FileStream class to
write single byte of data into file. Here, we are using
OpenOrCreate file mode which can be used for read and
write operations.
• C# StreamWriter
• C# StreamWriter class is used to write characters to a
4. • C# StreamReader
• C# StreamReader class is used to read string from the
stream. It inherits TextReader class. It provides Read()
and ReadLine() methods to read data from the stream.
• C# Serialization
• In C#, serialization is the process of converting object
into byte stream so that it can be saved to memory, file
or database. The reverse process of serialization is
called deserialization.
• Serialization is internally used in remote applications.
• C# SerializableAttribute
• To serialize the object, you need to
apply SerializableAttribute attribute to the type. If you
don't apply SerializableAttribute attribute to the
type, SerializationException exception is thrown at
5.
6. • C# Deserialization
• In C# programming, deserialization is the reverse
process of serialization.
• It means you can read the object from byte
stream. Here, we are going to
use BinaryFormatter.Deserialize(stream) method
to deserialize the stream.
7. For more visit our website www.siri-kt.blogspot.com
Thanks for
Watching
More Angular JS TutorialsMore C sharp (c#) tutorials