0% found this document useful (0 votes)
13 views5 pages

C# File I/O Basics and Classes

Uploaded by

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

C# File I/O Basics and Classes

Uploaded by

gracejamu4
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

C# - File I/O

C# - File I/O
• 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 the output
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 [Link] 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 [Link] namespace:
I/O Class Description
BinaryReader Reads primitive data from a binary stream.
BinaryWriter Writes primitive data in binary format.
Directory Helps in manipulating a directory structure.
DirectoryInfo Used for performing operations on directories.
DriveInfo Provides information for the drives.
File Helps in manipulating files.
FileInfo Used for performing operations on files.
FileStream Used to read from and write to any location in a file.
MemoryStream Used for random access to streamed data stored in memory.
Path Performs operations on path information.
StreamReader Used for reading characters from a byte stream.
StreamWriter Is used for writing characters to a stream.
StringReader Is used for reading from a string buffer.
StringWriter Is used for writing into a string buffer.
The FileStream Class
• The FileStream class in the [Link] namespace helps in reading
from, writing to and closing files.
• You need to create a FileStream object to create a new file or open an
existing file.
• The syntax for creating a FileStream object is as follows:
• FileStream <object_name> = new FileStream( <file_name>, <FileMode Enumerator>,
<FileAccess Enumerator>, <FileShare Enumerator>);

• For example, we create a FileStream object F for reading a file named


[Link] as shown:
• FileStream F = new FileStream("[Link]", [Link], [Link],
[Link]);

You might also like