System.IO Namesapce in C#
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).
From the above definition of file, the C# provides a namespace that
enable us to manipulate file in C# called System.IO.
System.IO is a namespace and it contains a standard IO (input/output) types such as classes, structures, enumerations, and delegates to perform a read/write operations on different sources like file, memory, network, etc.
System.IO Classes
The table below shows
different type of classes that
exists in System.IO namespace
to perform different operations like creating files, writing to files, reading
from files, etc.
Class |
Description |
BinaryReader |
This class is useful
to read primitive data types from a binary stream |
BinaryWriter |
It is useful to
write primitive types in binary format |
BufferedStream |
This class is useful
to read and write bytes from other streams |
Directory |
This class provides
methods to manipulate the directories and subdirectories such as Create and
Move etc |
File |
The class provides
methods to manipulate files like Create, Copy, delete, move etc |
FileStream |
It is useful to
read/write bytes from/to files |
MemoryStream |
The class is use to
read or write bytes that are store in memory |
Path |
It is use to perform
operations on directory path information |
Stream |
This class is an
abstract class and it will provide a methods to transfer bytes to the source. |
StreamReader |
This class is useful
to read a characters from stream by converting bytes into characters using an
encoded value. |
StreamWriter |
This class is useful
to write a characters to stream by converting characters into bytes using an
encoded value. |
StringReader |
This class is useful
to read from a string. |
StringWriter |
This class is useful
to write information to string. |
TextReader |
This class is useful
to read a sequential series of characters. |
TextWriter |
This class is
abstract and it is useful to write a sequential series of characters. |
System.IO Structures
The table below shows the different type of structures which exists in System.IO
namespace.
Structure |
Description |
WaitForChangedResult |
This structure will
contain information on the changes that occurred. |
System.IO Enumerations
The table below shows the different type of enumerations which exists in System.IO namespace.
Enumeration |
Description |
DriveType |
This will define constants for drive types. |
FileAccess |
It defines constants for reading, write, or read/write access
to a file. |
FileAttributes |
It provides attributes for files and directories. |
FileMode |
It specifies how an operating system will open the file. |
FileOptions |
It provides an advanced options for creating a filestream
object. |
FileShare |
It contains constants to control the access of filestream
objects. |
HandleInheritability |
It is useful to specify whether the underlying handle is
inheritable by child processes. |
NotifyFilters |
It specifies the changes to watch for in a file or folder. |
SearchOption |
It will specifies whether to search the current directory or
the current directory and all subdirectories. |
SeekOrigin |
It will specifies the position in a stream to use for seeking. |
WatcherChangeTypes |
It will specifies the changes that might occur to a file or
directory. |
System.IO Delegates
The table below shows the different type of delegates which exists in System.IO namespace.
Delegate |
Description |
ErrorEventHandler |
This
will represent a method that will handle the error event of a
FileSystemWatcher object. |
FileSystemEventHandler |
It
will represent a method that will handle the changed, created, or deleted
event of a FileSystemWatcher class. |
RenamedEventHandler |
It
will represent a method that will handle the renamed event of a
FileSystemWatcher class. |
Comments
Post a Comment